LinuxQuestions.org
Review your favorite Linux distribution.
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, 11:19 PM   #1
Feynman
Member
 
Registered: Aug 2010
Distribution: Gentoo
Posts: 62

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, 11:36 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,487

Rep: Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077
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, 11:39 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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, 11:44 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
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, 03:20 PM   #5
Feynman
Member
 
Registered: Aug 2010
Distribution: Gentoo
Posts: 62

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, 01:37 AM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
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, 10:57 AM   #7
Feynman
Member
 
Registered: Aug 2010
Distribution: Gentoo
Posts: 62

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


Reply

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 12:51 PM
LXer: Parallel Machine Learning Toolbox on Linux LXer Syndicated Linux News 0 11-22-2006 03:21 AM
Identify current mode of a file scbops Programming 2 07-03-2006 09:41 AM
identify cpu hogs edgjerp Mandriva 5 12-14-2004 07:17 AM
Switching off a CPU of a multiple CPU machine kravisudhakar Linux - General 1 12-26-2003 11:13 AM


All times are GMT -5. The time now is 03:08 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration