2

我将 mpi 安装到 Windows 中,我可以使用它的库。问题是我写的时候在windows中

mpiexec -n 4 proj.exe 

进入命令提示符它不会进行正确的操作。4 个不同的进程分别使用整个代码文件。它们的行为不像仅在 MPI_Init 和 MPI_Finalize 行中工作的并行进程。我该如何解决这个问题?是否不可能在 Windows 中使用 MPI。

Ps:我正在使用 Dev c++

4

1 回答 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;  
}  
于 2010-02-18T18:25:18.730 回答