第2回並列ゼミ - 知的システムデザイン研究室
第2回並列ゼミ - 知的システムデザイン研究室
第2回並列ゼミ - 知的システムデザイン研究室
- No tags were found...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
3 MPI MPI , , . ,OS . , OS ,LINUX . , forte,Debian/GNULinux2.2 MPICH( 1.2.1-6) . , 1 , 40 .MPICH , , , . ,MPI PVM . , rsh, .3.1 MPI ,MPI . , , mpirunmpicc. 1: forte MPI lib , MPICH .include ,lib,MPICH . ,mpi.h.util , . , ,machines.LINUXmpirun, , IP .bin , , mpi .WWW ,MPICH html .man ,man mpich .3
Figure 3: Adding a breakpoint.6. Press F8 or click debug button to start debugging.Figure 4: Debug button.7. Dev‐C++ executes the source code, starting from the main() function until it reachesline number 27. At this step, there should be text resulting from printf() command inline 26 in the console windows as in Fig. 5. Notice that the code in line number 27,which prints words asking for input, is not executed yet. Line number 27 is now paintedwith blue. Blue line indicates the current line to be executed in the debugging process.Figure 5: Output Console at Line 27.
MPI . , machines.LINUX. 4 4: MPI ,MPI , ID , . , ,IF , . ID MPI , , .5 MPI-CH 5.1 C MPI ,C mpicc. MPI ,C MPI . , ., .✓✏bash$ mpicc cpi.c -o cpi✒✑5.2 MPI , .✓✏bash$ mpirun -np 8 cpi✒✑-np, . . ,cpi. , , . , , . .5 . , MPICH , . ,MPI-2, .6 MPI-CH 6.1 MPI , MPI .6 ., , MPI SIMD . , , .6
mpirun -np 5: mpirun MPI , MPI COMM WORLD . , MPI COMM RANK . 1 , . , MPI Comm rank , ,if(rank == 0){ //}. , 8 .6.2 MPI MPI-1 127 . 6.2.1 , . , .MPI , . , , , . ,n , ,0,1,2, n-1 .6.2.2 , .1. , . , , .2. , .3. , .1) tag.2)communicator .6.2.3 MPI . 1 1 , , , , , . , .1 1 1. ✓MPI SEND(buffer,count,datatype,destination,tag,communicator)✒✑buffer:,count:,datatype:,destination:,tag communicator:2. ✏7
#include"mpi.h"int main(int argc,char**argv){int myrank;MPI_Init(&argc,&argv);MPI_Comm_rank(MPI_COMM_WORLD,&myrank)MPI_Status status;MPI_Finalize();} 6: MPI 8
7: if(myrank==0){}if(myrank==1){} 8: ✓MPI RECV(buffer,count,datatype,source,tag,communicator,status)✒✑, MPI ANYSOURCE . MPI ANY TAG .source:,status:, , , . , , status .3. ✓MPI SENDRECV(sendbuf,count,datatype,tag,communicator,recvbuf,count,datatype,tag,communicator)✒✑,MPI SEND MPI RECV , .4. MPI SENDRECV ( 10)., , , .✏✏9
int buf2[100];error=MPI_Send(buf2,5,MPI_INT,1,1234,MPI_COMM_WORLD);error =MPI_Recv(buf1,5,MPI_INT,0,1234,MPI_COMM_WORLD,&status);int a[50];error=MPI_Send(a,20,MPI_INT,1,5678,MPI_COMM_WORLD);int n;error=MPI_Send(&n,1,MPI_INT,1,1111,MPI_COMM_WORLD); 9: MPI 10
10: .1. ✓✒MPI BCAST(sendbuf,count,datatype,root,communicator), ( 11).✏✑ 11: .✓2. MPI GATHER(sendbuf,count,datatype,recvbuf,datatype,communicator)✒ ( 12).✏✑ 12: MPI GATHER .3. MPI SCATTER. . , ( 13).4. MPI ALLGATHER. .GATHER . ,ALLGATHER ( 14).5. MPI ALLTOALL. , . SCATTER . ,ALLTOALL ( 15).11
13: MPI SCATTER . 14: MPI ALLGATHER . 15: MPI ALLTOALL .12
URL .http://hamic6.ee.ous.ac.jp/software/mpich-1.1.2/6.3 MPI 6.3.1 1[]_____________________________________________________________________________#include "mpi.h" // int main(int argc, char **argv){int numprocs, myid;MPI_Init(&argc,&argv); // MPI ()MPI_Comm_size(MPI_COMM_WORLD, &numprocs);//MPI_Comm_rank(MPI_COMM_WORLD, &myid);// rank /* */MPI_Finalize(); // MPI return();}______________________________________________________________________________6.3.2 2[hello ]______________________________________________________________________________#include #include "mpi.h"int main(int argc, char *argv[]){int myid,procs,src,dest,tag=1000,count;char inmsg[10],outmsg[]="hello";MPI_Status stat;MPI_Init(&argc,&argv);MPI_Comm_rank(MPI_COMM_WORLD,&myid);count=sizeof(outmsg)/sizeof(char);if(myid == 0){src =1;dest =1;/*"hello"*/MPI_Send(outmsg,count,MPI_CHAR,dest,tag,MPI_COMM_WORLD);13
MPI_Recv(inmsg,count,MPI_CHAR,src,tag,MPI_COMM_WORLD,&stat);printf("%s from rank %d\n",inmsg,src);}else{src =0;dest =0;MPI_Recv(inmsg,count,MPI_CHAR,src,tag,MPI_COMM_WORLD,&stat);MPI_Send(outmsg,count,MPI_CHAR,dest,tag,MPI_COMM_WORLD);printf("%s from rank %d\n",inmsg,src);}MPI_Finalize();return 1;}______________________________________________________________________________6.3.3 3[]______________________________________________________________________________#include #include #define M 1000000int main(int argc,char *argv[]){ int i,j,rank,pnum,data[M],local_sum=0,global_sum,N; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&rank); MPI_Comm_size(MPI_COMM_WORLD,&pnum); for(i=0;i
16: [1] Message Passing Library [2] 15