473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

preprocessor number of cpus

Hi,

I am currently using OpenMP (gcc 4.2.0) to do parallel computing on a
computer with a certain amount of cpu's.

I need the total number of cpu's as a variable in my code. So I was
wondering how I could do this. Does there exists a system call for that
or something or is the best way just to take this out of /proc/cpuinfo?

I also would like to use some preprocessor code in it to cancel out the
pragma directive of omp when I only have one cpu. Is there a way to
do this?

Thanks
Klaas
Apr 25 '06 #1
4 2605
Klaas Vantournhout wrote:
Hi,

I am currently using OpenMP (gcc 4.2.0) to do parallel computing on a
computer with a certain amount of cpu's.

I need the total number of cpu's as a variable in my code. So I was
wondering how I could do this. Does there exists a system call for that
or something or is the best way just to take this out of /proc/cpuinfo?

I also would like to use some preprocessor code in it to cancel out the
pragma directive of omp when I only have one cpu. Is there a way to
do this?


Not in a standard compliant way. You will need to ask this in
a group that is concerned with your particular cpu, or OpenMP
(I presume that's the multi-cpu lib), or possibly your platform,
OS, or hardware. You need to go outside the standard language,
so you need to go outside of htis news group.
Socks

Apr 25 '06 #2
Puppet_Sock wrote:
Klaas Vantournhout wrote:
Hi,

I am currently using OpenMP (gcc 4.2.0) to do parallel computing on a
computer with a certain amount of cpu's.

I need the total number of cpu's as a variable in my code. So I was
wondering how I could do this. Does there exists a system call for that
or something or is the best way just to take this out of /proc/cpuinfo?

I also would like to use some preprocessor code in it to cancel out the
pragma directive of omp when I only have one cpu. Is there a way to
do this?


Not in a standard compliant way. You will need to ask this in
a group that is concerned with your particular cpu, or OpenMP
(I presume that's the multi-cpu lib), or possibly your platform,
OS, or hardware. You need to go outside the standard language,
so you need to go outside of htis news group.
Socks


Note that presumably you want to know the number of CPUs at runtime, not
compile time. Thus a preprocessor pragma (or variable) would be nearly
useless to you. Most programs don't much care about the compiling
environment... they usually care about the execution environment.
Apr 25 '06 #3
Andre Kostur wrote:
Note that presumably you want to know the number of CPUs at runtime, not
compile time. Thus a preprocessor pragma (or variable) would be nearly
useless to you. Most programs don't much care about the compiling
environment... they usually care about the execution environment.


On the contrary, I would like to obtain it at compile time. That is why
I was wondering if there is some kind of preprocessor variable that
contains the number of cpus dynamically depending on the machine you
compile it on.
If this is possible I would be able to use the following code to exclude
the OpenMP (if I am right of course)

#if NCPU != 1
#include <omp.h>
#endif

....

#if NCPU != 1
#pragma omp parallel private(tid)
#endif

....

So does there exist a predefined number of processors or is this non
existent and do I have to use a define directive myself. And if this is
the case, can I at compile time change it automatically by , lets say a
make script?

Thanks

Klaas
Apr 26 '06 #4
Klaas Vantournhout wrote:
Andre Kostur wrote:

Note that presumably you want to know the number of CPUs at runtime, not
compile time. Thus a preprocessor pragma (or variable) would be nearly
useless to you. Most programs don't much care about the compiling
environment... they usually care about the execution environment.

On the contrary, I would like to obtain it at compile time. That is why
I was wondering if there is some kind of preprocessor variable that
contains the number of cpus dynamically depending on the machine you
compile it on.
If this is possible I would be able to use the following code to exclude
the OpenMP (if I am right of course)

#if NCPU != 1
#include <omp.h>
#endif

...

#if NCPU != 1
#pragma omp parallel private(tid)
#endif

...

So does there exist a predefined number of processors or is this non
existent and do I have to use a define directive myself. And if this is
the case, can I at compile time change it automatically by , lets say a
make script?

No. It's of no value in most cases.

You can set own and change it at compile time, but in a non-standard
way. Many compilers use -D to define preprocessor constants.

--
Ian Collins.
Apr 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Canneloni | last post by:
Xeon hyperthreaded CPUs show up as two CPUs in the cpuinfo file. So a dual Xeon machine appears as a quad processor. In Windows, it's the same thing. A dual Xeon will have 4 CPU charts...
205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
4
by: Jay Wolfe | last post by:
Hi, If I define a macro as follows #define COSTHETA cos(45.0*3.14159256/180.0) I believe that any time COSTHETA appears it is simply replaced by the defined text, which results in the...
2
by: spasmous | last post by:
I just found out MSVC++ doesn't unroll loops on any optimization setting. So I manually unrolled the inner loop of a slow part of my program... The result was a 2X gain in speed. So I'm wondering...
6
by: ludovicd | last post by:
Hi to all, There is my question, Let's say I got a fonction which takes a numeric argument long enough so that there has to be spaces in it to represent it correctly. (Ex. 0xf63a002c5ff0338ec...
1
by: Klaus Siegesleitner | last post by:
Hi all! sorry, my first posting to this newsgroup - hope everything works fine... I'm looking for a macro that converts an octal number assigned to a preprocessor symbol (via a simple #define)...
1
by: rcamarda | last post by:
I have been unsuccessful locating information about the maximum number of CPU's SQL Server 2005 Enterprise supports. However I did find info in a document about configuring a fail over cluster...
3
by: Shekar | last post by:
Is there a class/module/function in PHP that will help me identify the number of CPUs on a system? php_uname() does not provide that information. Though I can execute a system command, I do not...
11
by: John | last post by:
Is there a way to find the number of processors on a machine (on linux/ windows/macos/cygwin) using python code (using the same code/cross platform code)?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.