i dont know if its the right place to ask this question or not. If not
please suggest me.
MY working Environment is Linux with Quad Core hardware ( 4 CPU)
I have a simple time consuming c++ program.
Now in this working environment how do i check if my program is using
multiple CPU for execution or not.
I have tried using TOP -H command to check the CPU usage and then
later pressed 1. I can see all 4 CPU being used which under default
condition seemed to be idle.
Does that mean my program is using multiple CPU for executing its
instructions automatically.
If not, why do i see those percentage consumption in other CPUs?
If yes, how do i make my application only take one CPU for its
execution.
i am using g++ to compile my application.
take care
miztaken
> Now in this working environment how do i check if my program is using
> multiple CPU for execution or not.
You have to start by defining the question in a comprehensible way.
For example, if the program moves rapidly between CPUs but never uses
more than one at a time, is that using "multiple CPU for execution" or
not? If it tries to read a file from disk, and the disk I/O is handled
by another CPU, is that using "multiple CPU for execution" or not?
> I have tried using TOP -H command to check the CPU usage and then
> later pressed 1. I can see all 4 CPU being used which under default
> condition seemed to be idle.
The behavior will depend upon details about your scheduler. For
example, you may have a scheduler that makes the coolest CPU the
busiest. You may not.
> Does that mean my program is using multiple CPU for executing its
> instructions automatically.
Again, that's a poorly-defined question.
> If not, why do i see those percentage consumption in other CPUs?
There could be a ton of reasons:
1) Your program is only using one CPU at a time, but which CPU is
changing more rapidly than your tool can tell you.
2) Your program really is using more than one core at a time.
3) Other CPUs are doing other things, including perhaps I/O that
pertains to the program.
> If yes, how do i make my application only take one CPU for its
> execution.
Do you mean no more than one CPU? Or one particular CPU? And why use
the hottest CPU if the others are cooler? And if one particular CPU is
busy, say handing an IPI, why would you want your task to wait when
there are three non-busy cores?
What is it you are trying to do? Your question is the type of question
that usually indicates a person has no idea what they *really* want.
DS
The operating system treats a multi-core processor as
multiple processors.
The system can run separate threads or processes in
parallel on different processor cores.
You have to split your tedious problem into such pieces
that they can be run in parallel without disturbing the
data needed by each other. The pieces have then to be
run in separate threads to use the parallelism in hardware.
This applies to the code, regardless which language it
is written in.
--
Tauno Voipio
tauno voipio (at) iki fi
If you don't create any child tasks (threads/processes) then it's not going
to be running on multiple CPUs simultaneously.
>If not, why do i see those percentage consumption in other CPUs?
>If yes, how do i make my application only take one CPU for its
>execution.
sched_setaffinity
--
Alan Curry
All i am trying to do is to compute the time required to execute my c
program.
I haven't created a thread inside my program, its all the sequential
flow.
yes first part of my program read some data from file and stores in
memory and then rest
of the program use that data.
But my requirement is that i need to make sure that my program uses
only one CPU ( hot or cold), only one.
but when i run my program then i can see certain % consumption in all
4 CPU and i am baffled due to same?
what can be the reason?
> All i am trying to do is to compute the time required to execute my c
> program.
That's what the 'time' function is for.
> I haven't created a thread inside my program, its all the sequential
> flow.
> yes first part of my program read some data from file and stores in
> memory and then rest
> of the program use that data.
> But my requirement is that i need to make sure that my program uses
> only one CPU ( hot or cold), only one.
> but when i run my program then i can see certain % consumption in all
> 4 CPU and i am baffled due to same?
>
> what can be the reason?
There's no way to know. It's possible your process is moving from core
to core.
Your statement "make sure that my program uses only one CPU" is still
ill-defined. Do you mean one CPU at a time? Or do you demand it stay
on the same CPU the whole time it's running if it's using only one at
a time? And what if the interrupts generated by its file read
operations are completed on another CPU?
You haven't figured out yet what it is you actually want to do.
Perhaps what you really want to do is reboot your machine with a uni-
processor kernel and time your program. Perhaps not. It depends on
what your real question is, and you haven't quite asked it yet.
What are you going to do with this time? What meaning do you expect it
to have?
For example, do you expect that if you run four instances of your
program on this computer, it will take that long for them all to
complete? Or do you expect that if you run the program on a
uniprocessor machine, this is how long it will take to complete? Those
are two completely different questions.
What do you *really* want to know?
DS
> That's what the 'time' function is for.
time function gives the time for whole program execution.
i just need the time for certain portion of my program.
> Your statement "make sure that my program uses only one CPU" is still
> ill-defined. Do you mean one CPU at a time? Or do you demand it stay
> on the same CPU the whole time it's running if it's using only one at
> a time? And what if the interrupts generated by its file read
> operations are completed on another CPU?
yes, i want it to stay in same CPU all the time.
> You haven't figured out yet what it is you actually want to do.
> Perhaps what you really want to do is reboot your machine with a uni-
> processor kernel and time your program. Perhaps not. It depends on
> what your real question is, and you haven't quite asked it yet.
ya i will explore on this uni-processor kernel a little and see how it
goes.
> For example, do you expect that if you run four instances of your
> program on this computer, it will take that long for them all to
> complete? Or do you expect that if you run the program on a
> uniprocessor machine, this is how long it will take to complete? Those
> are two completely different questions.
yes i want to know if i run my program in uni processor machine, how
long will it take to complete.
the whole thing i am doing is, i want to test the performance of my
algorithm in uni processor machine so that i can compare its result
with what i am getting in parallel processing of the same algorithm.
But since i have quad core PC, so i want my program to stay in
uniprocessor all the time.
i hope i have cleared my problem.
miztaken
man gprof
> yes, i want it to stay in same CPU all the time.
man sched_setaffinity
man cpuset
--
John Hasler
jha...@newsguy.com
Dancing Horse Hill
Elmwood, WI USA