MultiTasking

Hi All,

I'm new to programing in c++ so please bare with me. Here's the problem, I have a list/vector of external job/programs I need to run. Some of the job/programs take ~10+ mins to complete and I have ~1000 jobs/programs to run. However, I have 12 CPUs to work with, so I would like to write a program to run 12 jobs/programs continously until all jobs/programs are complete. I don't know how to even start...

I known how to run all the jobs at once (but this would crash the computer) and I also know how to run 1 job at a time (but this takes too long).

Here is what would work to run 1 job at a time:

int main() {

// LOCATION OF FILES TO BE RUN
string fileLocation = "filesAreHere";
// Create A Vector Of File Names, Calls "getfilenames" Program
vector<string> files;
files = getfilenames(fileLocation);
int size = files.size();

// Start Loop To To Excute Files
int i=1;
while(i < size-1) {

system(files[i]);
++i;
}
return 0;
}

Thanks for any help,
Mike
Running multiple "jobs" at once sounds like parallel computing.
This is called multi-threading, and there isn't much support for it right now, as it's relatively new. I don't know what platform you're using, but boost is cross-platform, and it has a multi-threading library already implemented in it. Get boost and research the 'thread' library.
I thought I might be able to do this with "fork". I have been able to write a script that does this, I will just run the script from my c++ program.
Why bother with C++ at all? jobs | wc -l returns the number of running jobs.
Topic archived. No new replies allowed.