[Omp] Detecting No. of processors during OpenMP execution

Bronis R. de Supinski bronis at llnl.gov
Tue Jan 18 16:44:30 PST 2005


Waibhav:

Re:
>I had thought of using "hostname". But will it work when the process is 
>running on a multi-processor single
>node that has shared memory? I was under the impression that the 
>"hostname" would refer to the node
>and would output the same name independent of the actual cpu that is 
>executing a thread. Perhaps, I
>should have rephrased the question: Is it possible to monitor/find out 
>which of the multiple cpus on a single
>node is executing a particular thread called from OpenMP parallel 
>execution routine? Is there a cpu_id
>for each physical cpu on a given node in a cluster?

Typically, yes. How to determine it varies widely by
OS (and don't just say Unix)/architecture. Please 
consult the source code of the Sphinx suite for a
(perhaps somewhat dated) header file that unifies
a subset of the possibilities (and comes with no 
guarantees). See:

http://www.llnl.gov/CASC/sphinx/sphinx.html

in particular, look at sphinx_threads.h...

Bronis


>
>Apologies for not being clear when I stated my problem.
>
>Thanks.
>
>-waibhav
>
>Marina Kraeva wrote:
>
>> Hello,
>>
>> First of all, you can't set the number of processors from within your 
>> program. The omp_set_num_threads function specifies the number of 
>> threads, not processors.
>>
>> To find out the number of threads that are running specific piece of 
>> the code you can call omp_get_num_threads.
>>
>> As I understood you would like to know on what processors your threads 
>> are running. You can try to use something like this:
>>
>>   #include <unistd.h>
>>   ...
>>   char name[50];
>>   size_t len;
>>   ...
>>   gethostname(name, len);
>>   printf("thread %d is running on hostname %s\n",MyId,name);
>>
>> Marina.
>>
>> Waibhav Tembe wrote:
>>
>>> Hello,
>>>
>>> I am using OpenMP for my application on Linux system using Intel's 
>>> ecc compiler with -openmp option on a node that has multiple 
>>> processors sharing memory. Although there is a facility in OpenMP to 
>>> set the number of processors (by selecting omp_ set_num_threads ), I 
>>> was  wondering if there is any way (perhaps from the OS)  to check 
>>> the actual number of processors that were used. For example, if I set 
>>> num. of threads = 8 and for some reason, only 4 processors are used 
>>> (each processors typically executes 2 threads), then I would like to 
>>> be able to generate a report that captures this information. Its 
>>> going to be used to test the effectiveness of some tools in using the 
>>> parallel processing capabilities. Is there any way to find IDs of the 
>>> processors that were used for a specific run of a program?
>>> I thought of issuing a "ps" command during execution. But I am hoping 
>>> that there is some smarter way. Any pointers in this direction are 
>>> welcome!
>>>  
>>> Thanks a lot.
>>>
>>> w
>>>
>>>
>>>
>>> _______________________________________________
>>> Omp mailing list
>>> Omp at openmp.org
>>> http://openmp.org/mailman/listinfo/omp_openmp.org
>>>
>>>
>
>-- 
>Waibhav Tembe.
>
>
>
>_______________________________________________
>Omp mailing list
>Omp at openmp.org
>http://openmp.org/mailman/listinfo/omp_openmp.org





More information about the Omp mailing list