LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-01-2010, 10:19 PM   #1
Feynman
Member
 
Registered: Aug 2010
Distribution: XUbuntu
Posts: 71

Rep: Reputation: 15
Question How to identify current CPU in a parallel machine


I do not know much about parallel computing, but I do have access to a few cpus. I am trying to write a program compatible for multiple cpus, but to do it, I need to ensure unique directories. I have figured out that the time of creation, process id, and cpu id form a unique combination I can use to name files (up to the degree of accuracy of the internal timer).
Anyway, I am using perl. I know how to find the process id and I know I can get the time pretty easily, but as I said, I do not know much about hardware or parallel computing. All I need is a way to identify each cpu in the system and I am set for half of my program (the other half is significantly more straightforward and is mainly about text parsing.)

So anyway using terminal, perl, etc., I could access this identification? Or could someone at least tell me the name of what I am looking for? I have seen the words "ip" "MAC" "hostid" and a bunch of other "id" things come up in my googling, but I really cannot figure out which is the one relevent to me.

Thank you.
 
Old 09-01-2010, 10:36 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
IIRC, strictly speaking you can never find out what CPU you are on (when there is more than one). To find out you have to be interrupted (!!!), and there's no guarantee you'll be redispatched on the same one.
Highly likely but not guaranteed.

If that is good enough, have a look at /proc/<pid>/stat for processor.
 
Old 09-01-2010, 10:39 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Do any of these help?

http://node1.yo-linux.com/cgi-bin/ma...ommand=taskset
http://www.ibm.com/developerworks/li...-affinity.html
http://software.intel.com/en-us/arti...ssor-affinity/



Cheers,
Tink
 
Old 09-01-2010, 10:44 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
On a *nix system, pid is guaranteed to be unique at any given time (that's how the kernel keeps track). If the sequence num wraps around, the kernel will not create a 2nd process with the same pid as a current process; it merely skips that number. Usually pids are up to 4 digits long (maybe 5 on some systems?).
Adding the time in epoch seconds would be sufficient to ensure uniqueness across time if the dirs last acrosss that timespan.
cpu-id is not required.
If you are using threads instead of sub-processes, then concat the thread id to the name ie pid-tid-timestamp_in_seconds.
 
Old 09-02-2010, 02:20 PM   #5
Feynman
Member
 
Registered: Aug 2010
Distribution: XUbuntu
Posts: 71

Original Poster
Rep: Reputation: 15
chrism01--that should be fine ASSUMING more than one cpu cannot use the same PID at the same time. I figured they could, but like I said, I do not know much about parallel computing.

Thanks
 
Old 09-03-2010, 12:37 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
As I said, it depends if you are using threads or not.

On a multi-processor system and using only full Unix processes (not threads), a given process will normally be moved back and forth between cpus by the kernel, depending on the load on each cpu at each pt in time.
IE, it can only be running on one cpu at at any given pt in time (where cpu = core for multi-core chips).

If you use threads, they do not have separate process ids; they are Light Weight Processes (LWPs) within their owning Unix process (ie 1 pid = many threads).
In this case, each thread can run on separate cpus (at the same time), so the owning process appears to run on multiple cpus simultaneously.

Note that there is a sched_setaffinity http://linux.die.net/man/2/sched_setaffinity option in C for processes, but it's rarely used by programmers.
Normally the kernel does a better job of schduling that you would manually.

For Perl, there is no builtin cmd, but there is a Module http://search.cpan.org/~mob/Forks-Su...CpuAffinity.pm or just search for others at search.cpan.org.
 
Old 09-03-2010, 09:57 AM   #7
Feynman
Member
 
Registered: Aug 2010
Distribution: XUbuntu
Posts: 71

Original Poster
Rep: Reputation: 15
Ok, thanks for the info!
 
  


Reply

Tags
computing, cpu, id, ip, parallel, perl



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Current 03/2010 - hplip and the parallel port (pp-build=no) hotchili Slackware 0 03-05-2010 11:51 AM
LXer: Parallel Machine Learning Toolbox on Linux LXer Syndicated Linux News 0 11-22-2006 02:21 AM
Identify current mode of a file scbops Programming 2 07-03-2006 08:41 AM
identify cpu hogs edgjerp Mandriva 5 12-14-2004 06:17 AM
Switching off a CPU of a multiple CPU machine kravisudhakar Linux - General 1 12-26-2003 10:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration