Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parallel processing

Status
Not open for further replies.

tjkun

Programmer
Jan 23, 2002
15
0
0
TH
How to write program which make use of two CPU...
Please help...

Any resource would be appreciate
 
The usual way of doing this is to use threads. Several threads of execution can be going at a time in a single program.

Look at the threads library for your compiler and operating system for info on how to use threads.

How to actually write the program is another matter, and depends on what exactly you want it to do. It may not even be a good idea to use multi-threading for certain applications; good multi-threaded programs run faster than single-threaded ones, but bad multi-threaded programs are slower than single-threded ones.
 
This is, of course, oriented towards using multiple processors in different machines -- I dont know if any of it applies to multiple processors in one machine, but its a start either way.
 
Thanks for you guys suggestion...but what I'd like to do is how to, for example, I have program which handle two big process...one is calculate...and one is write ..how can I specifically assign the calculation to one cpu and writing to another cpu...

????desperate...???help please
 
You can't (under any OS I know of) "assign" a thread or process to a certain CPU. All you can do is say to the OS, "Do these two things at the same time if at all possible."

Here's a simple Unix example of what you might want:


[tt]#include <unistd.h>

int main()
{
if ( fork() )
calculator();
else
writer();

return 0;
}
[/tt]

That doesn't use threads, it actually creates two running processes. The fork makes a copy the process and returns 0 in the child process and non-zero (the child's id) to the parent process. So in this case, the parent does the stuff under if, and the child does the stuff under else.

Of course, if your processes need to communicate (like yours seem to), this introduces the problem of interprocess communication... pipes, message queues, semaphores, and all kinds of messy stuff you don't have with threads.

That's why you should look at your documentation and see what kind of thread support you have. Chances are you have POSIX's pthreads. When you find out what you have access to, ask for help here on using the particular thread library you have.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top