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++

Nicolás Ozimica
  • 9,481
  • 5
  • 38
  • 51
Iguramu
  • 2,080
  • 5
  • 26
  • 30

1 Answers1

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;  
}  
Community
  • 1
  • 1
J Teller
  • 1,421
  • 1
  • 11
  • 14
  • 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). – J Teller Feb 18 '10 at 18:26