Hi guys,

I'm wondering whether it's possible to implement MPI to execute a process in parallel from deep within a C++ solution.

I've created a solution on VS2005 that links to several static libraries, and within one of these libraries there is a set series of tasks that require execution many times - they're independent so I'd like them to execute them using MPI if possible to speed up the run time.

The pseudo-code is:

Code:
for(i = 0; i < n; i++)       // n is number of times to execute process
{
    PerformTask(data[i]);    // perform the tasks required for each iteration of process
}
So, instead of conducting the tasks within PerformTask() in series n times, I want to split the array data between multiple processes such that they can each be allocated an even proportion of data to perform the tasks on. Pretty textbook reason for wanting MPI, right?

Now, I've read up and understood the basics of MPI implementation, but all the examples I've seen are called within the main() function of the program. But I need to do all this from within a static library, is this possible?

I've made some early attempts at implementing this, but get an error indicating the process wasn't initialised: "Error encounted before initializing MPICH", which I assumed would be due to trying to make the MPI calls outside of the main() function.

By the way, I have tested the set-up of MPI within VS2005 with some simple examples, and they execute without issue.

Cheers,

Jonathan

P.S. If there are any alternative methods to MPI, then I'm afraid I can't use them, as I want this to project to eventually run on the department supercomputer, and that requires MPI-implemented parallel programming