![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| forking in multithreaded program | skyrulz | UNIX for Advanced & Expert Users | 0 | 04-22-2009 02:57 AM |
| execute command multithreaded util without programming | umen | Shell Programming and Scripting | 0 | 12-07-2008 06:01 AM |
| Having trouble writing a basic shell program | SeanWuzHere | Shell Programming and Scripting | 3 | 11-30-2006 01:41 PM |
| basic math program 4 child | perleo | High Level Programming | 9 | 10-22-2002 04:51 PM |
| Getting errno in a Multithreaded program | S.Vishwanath | High Level Programming | 2 | 03-25-2002 09:58 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Basic multithreaded program
I'd like to write a program (I'm flexible on language; C/C++ was my original idea but a scripting language would probably be better) that runs hundreds of programs, but only N = 4 (say) at a time. The idea is to keep all the cores on a multicore machine busy.
How can I do this? In particular, I'd like a library call I can make in some appropriate language that can
|
|
||||
|
The program will read in a text file with a bunch of numbers, do some processing on them, then create an array based on those numbers. Each element of the array will be passed through a function which will create an appropriate data set for that entry. The data will be used to create a temporary file and a command line argument using that file.
I didn't think this was relevant before so I didn't mention it. Basically, the program does some work and comes up with a list of commands to run. Quote:
Quote:
This one I'm working on does not, but I'd like a method that could send input because other similar programs I'll write will probably need to do this. -----Post Update----- I just changed my OS to 64-bit Ubuntu 9.04. The programs are processor-intensive 64-bit programs with small-medium memory footprints. |
|
|||||
|
Quote:
|
|
||||
|
Quote:
So instead I write a program to find the most efficient solution for each piece, calculate its likely runtime, solve an approximate bin-packing problem, and schedule each across a user-tunable number of processors. |
|
|||||
|
OK, from what you've posted 'till now, the basic structure would be something like this (pseudo-code)
Code:
Read numbers from file
Process them
Create output files
Create array of commands to run
Total processes=0
While there are commands left
pop a command from the stack
fork() a subprocess
In the child
system() the command
In the parent
Total processes++
If total processes >= 4
wait() until any process returns
Alternatively, you could run exec() the program yourself, to reduce the fork-rate, but I'm not sure how well this would work. Plus, with shed_setaffinity you can set the affinity of the processes (direct it which CPU to use), but you'd have to track which CPU the last process used. Anyone with more experience with algorithms has a better idea? |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| multicore, threading |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|