MPICH anzhulin@sohu.com 1 MPICH for Microsoft Windows 1.1 MPICH for Microsoft Windows Windows NT4/2000/XP Professional Server Windows 95/98 TCP/IP MPICH MS VC++ 6.x MS VC++.NET Compaq Visual Fortran 6.x Intel Fortran gcc g77 MPICH 1.2 MPICH http://www-unix.mcs.anl.gov/mpi/mpich/download.html Windows mpich.nt.1.2.5.exe http://www-unix.mcs.anl.gov/~ashton/mpich.nt/ 1.3 MPICH mpd.exe 1.4 MPICH MPICH MPICH mpich\mpd\bin\mpiregister.exe Page 1 of 15
MPIRegister MPICH MPICH -> ->MPICH->mpd-> MPICH Configuration tool MPICH Configuration tool Select 1 MPICH Apply 2 OK 3 1.5 MPICH MPICH C Fortran MPI+C MPI+Fortran Visual C++ 6.0 Compaq Visual Fortran 6.5 Visual Fortran 5.0 1.5.1 Visual C++ 6.0 Visual C++ 6 MPI+C Page 2 of 15
1 Visual C++ 6 Develop Studio 2 Win32 Console Application 3 Alt+F7 Visual C++ 2 4 C/C++ Win32 Debug Code Generation Debug Multithreaded Page 3 of 15
5 C/C++ All Configurations Preprocessor Additional include directories MPICH Visual C++ 3 6 All Configurations Input Additional library path MPICH Visual C++ 4 Page 4 of 15
7 All Configurations General Object/library modules ws2_32.lib OK Common Options ws2_32.lib Visual C++ 5 8 Win32 Debug General Object/library modules mpichd.lib OK Project Options mpichd.lib Visual C++ 6 Page 5 of 15
9 Win32 Release General Object/library modules mpich.lib OK Project Options mpich.lib Visual C++ 7 1.5.2 Compaq Visual Fortran 6.5 Compaq Visual Fortran 6.5 Develop Studio Visual C++ 6.0 1.5.3 Visual Fortran 5.0 MPICH Visual Fortran 5.0 Visual Fortran 5.0 Link.exe Microsoft Develop Studio 97 5.00.7022 Visual Fortran 5.0 MPI --------------------Configuration: testran - Win32 Debug-------------------- Compiling Fortran... C:\Program Files\DevStudio\MyProjects\testran\test.for Linking.....\..\..\..\MPICH\SDK\Lib\mpich.lib : fatal error LNK1106: invalid file or disk full: cannot seek to 0x3ea20b5c Error executing link.exe. testran.exe - 1 error(s), 0 warning(s) Link.exe Visual C++ 6.0 Link.exe \DevStudio\VC\BIN Link.exe Visual C++ 6.0 Microsoft Windows DDK Microsoft MASM Link.exe Link.exe Visual Fortran 5.0 MPI+Fortran Visual Fortran 5.0 Develop Studio Visual C++ 6.0 Page 6 of 15
Fortran MPI MPICH Project->Add to project->files MPI Visual Fortran 5.0 1.6 MPICH\SDK\Examples\nt\Basic π VC MPICH MPIRun -> ->MPICH->mpd->MPIRun Page 7 of 15
MPI.. Run 2 MPI MPI MPI MPI C Fortran 2.1 MPI MP I int MPI_Init(int *argc, char ***argv) 2.2 MPI MPI int MPI_Finalize(void) 2.3 n 0 n 1 int MPI_Comm_rank(MPI_Comm comm, int *rank) [ IN Comm ] [ OUT rank ] COMM 2.4 int MPI_Comm_size(MPI_Comm comm, int *SIZE) [ IN comm ] [ OUT size ] COMM Page 8 of 15
2.5 buf count datatype dest int MPI_Send(void* buf, int count, MPI_Datatype Datatype, int dest, int tag, MPI_Comm comm) [ IN buf ] [ IN count ] [ IN datatype ] [ IN dest ] [ IN tag ] [ IN comm ] 2.6 source count datatype buf int MPI_Recv(void* buf, int count, MPI_Datatpye datatype, int source, int tag, MPI_Comm comm, MPI_Status *status) [ OUT buf ] [ IN count ] [ IN datatype ] [ IN source ] [ IN tag ] [ IN comm ] [ OUT status ] 2.7 buf count datatype root int MPI_Bcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) [ IN/OUT buf ] [ IN count ] Page 9 of 15
[ IN datatype ] [ IN root ] [ IN comm ] 2.8 int MPI_Gather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype Recvtype, int root, int comm) [ IN sendbuf ] [ IN sendcount ] [ IN sendtype ] [ OUT recvbuf ] [ IN recvcount ] [ IN recvtype ] [ IN root ] [ IN comm ] 3 MPI MPI MPI Data 3.1 1 7 ArraySize[ 0] = 7 3 size = 3 Page 10 of 15
AverageLin enumber = ArraySize[0] / size HeavyProcessorNumber = ArraySize[0] mod size AverageLineNumber + 1 rank AverageLineNumber + 1 MyLineNumber = AverageLineNumber rank < HeavyProcessorNumber rank HeavyProcessorNumber MPI SendArray Data MPI Page 11 of 15
0 0 3.2 3.3 #include"mpi.h" #include<iostream.h> #include<fstream.h> void main(int argc,char *argv[]) { // MPI int rank,size; MPI_Status Status; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&rank); MPI_Comm_size(MPI_COMM_WORLD,&size); // const int MAXX=8,MAXY=3; const int MAXPROCESSOR=64; float Data[MAXX][MAXX]; int ArraySize[2]; int i,j,k; // if (rank == 0) { ifstream in("input.txt"); in>>arraysize[0]>>arraysize[1]; } for (i=1; i<=arraysize[0]; i++ ) for (j=1; j<=arraysize[1]; j++) in>>data[i][j]; // Page 12 of 15
MPI_Bcast(ArraySize,2,MPI_INT,0,MPI_COMM_WORLD); // int AverageLineNumber,HeavyProcessorNumber,MyLineNumber; int CurrentLine,StartLine,SendSize; float SendArray[MAXX*MAXY]; // AverageLineNumber=ArraySize[0] / size; HeavyProcessorNumber=ArraySize[0] % size; if (rank < HeavyProcessorNumber) MyLineNumber=AverageLineNumber+1; else MyLineNumber=AverageLineNumber; // 0, if (rank == 0) { CurrentLine=ArraySize[0]; for (i=size-1; i >= 0; i--) { SendSize=0; if (i < HeavyProcessorNumber) StartLine=CurrentLine-AverageLineNumber; else StartLine=CurrentLine-AverageLineNumber+1; for (j=startline; j <= CurrentLine; j++) for (k=1; k <= ArraySize[1]; k++) SendArray[SendSize++]=Data[j][k]; if (i!= 0) MPI_Send(SendArray,SendSize, MPI_FLOAT,i,10,MPI_COMM_WORLD); CurrentLine=StartLine-1; } } // 0 else MPI_Recv(SendArray,MyLineNumber*ArraySize[1], MPI_FLOAT,0,10,MPI_COMM_WORLD,&Status); // float *Sum=new(float); //, *Sum=0; for (i=0; i < MyLineNumber*ArraySize[1]; i++) *Sum+=SendArray[i]; float AllSum[MAXPROCESSOR]; // 0 MPI_Gather(Sum,1,MPI_FLOAT,AllSum,1,MPI_FLOAT,0,MPI_COMM_WORLD); // 0,, if (rank == 0) { Page 13 of 15
} *Sum=0; for (i=0; i < size; i++) *Sum+=AllSum[i]; cout<<"the Sum of the Array is:"<<*sum<<endl; //MPI MPI_Finalize(); } 3.4 MPI MPI 4 FAQ Q MPICH Windows Linux A MPI Windows Linux MPICH Socket Q Unhandled exception caught in RedirectIOThread A MPIRun 0 Q MPI_RECV : Message truncated A MPI_RECV MPI_SEND MPI_RECV Q Error 64 GetQueuedCompletenessStatus failed A MPI_RECV MPI_SEND MPI_RECV MPI_SEND Q Failed to launch the root process: c:\cpi.exe LaunchProcess Failed, A MPIRegister Page 14 of 15
Page 15 of 15