2

I installed mpi into windows and I can use its libraries. The problem is that in windows when I write

mpiexec -n 4 proj.exe 

into command prompt it does not make the proper operations. 4 different processes uses the whole code file separately. They don't behave like parallel processes that are working only in the MPI_Init and MPI_Finalize rows. How can I fix this problem? Is it impossible to work MPI in Windows.

P.s : I am using Dev c++

0

1 Answer 1

17

MPI is running correctly by what you said -- instead your assumptions are incorrect. In every MPI implementation (that I have used anyway), the entire program is run from beginning to end on every process. The MPI_Init and MPI_Finalize functions are required to setup and tear-down MPI structures for each process, but they do not specify the beginning and end of parallel execution. The beginning of the parallel section is first instruction in main, and the end is the final return.

A good "template" program for what it seems like you want would be (also answered in How to speed up this problem by MPI):

int main(int argc, char *argv[]) {
    MPI_Init(&argc, &argv);  
    MPI_Comm_size(MPI_COMM_WORLD,&numprocs);  
    MPI_Comm_rank(MPI_COMM_WORLD,&myid);

    if (myid == 0) { // Do the serial part on a single MPI thread
        printf("Performing serial computation on cpu %d\n", myid);
        PreParallelWork();
    }

    ParallelWork();  // Every MPI thread will run the parallel work

    if (myid == 0) { // Do the final serial part on a single MPI thread
        printf("Performing the final serial computation on cpu %d\n", myid);
        PostParallelWork();
    }

    MPI_Finalize();  
    return 0;  
}  
Sign up to request clarification or add additional context in comments.

1 Comment

Also, if you actually post some source code, maybe we could help more with how getting your MPI program to run correctly. Just based on your very brief description, you may be trying to use shared-memory to communicate (which doesn't work, by design, in MPI).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.