1 / 7

MPI を使った加算 

MPI を使った加算 . 齋藤グループ 小林直樹. 2003.5.16. 1. 2500. 2501. 5000. 5001. 7500. 7501. 10000. プロセス 0. プロセス 1. プロセス 2. プロセス 3. 配列 A. 部分和 SUM. 部分和 SUM. 部分和 SUM. 部分和 SUM. 総和 GSUM. 概念図. mpif.h : MPI で利用する定数などの型宣言がなされている定義ファイル. MPI_INIT : MPI 環境の初期化. MPI_COMM_RANK : プロセス情報取得.

anana
Download Presentation

MPI を使った加算 

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MPIを使った加算  齋藤グループ 小林直樹 2003.5.16

  2. 1 2500 2501 5000 5001 7500 7501 10000 プロセス0 プロセス1 プロセス2 プロセス3 配列A 部分和SUM 部分和SUM 部分和SUM 部分和SUM 総和GSUM 概念図

  3. mpif.h : MPIで利用する定数などの型宣言がなされている定義ファイル MPI_INIT : MPI環境の初期化 MPI_COMM_RANK : プロセス情報取得 MPI_COMM_SIZE : プロセス数情報取得する  MPIプログラム (1/3) program summation include ‘mpif.h’ integer myrank, tnode, error DIMENSION A(10000) call mpi_init(error) call mpi_comm_rank(MPI_COMM_WORLD, myrank, error) call mpi_comm_size(MPI_COMM_WORLD, tnode, error)

  4. MPIプログラム (2/3) tnode=4 myrank=0,1,2,3 DO 10 I = 1, 10000 A(I) = real(I) 10 CONTINUE lb = 10000 / tnode lc = mod(10000,tnode) if(myrank+1.le.lc) then is = myrank*lb +myrank +1 ie = is + lb else is = myrank*lb+lc+1 ie = is + lb - 1 end if myrank=0 is=0x2500+0+1=1 ie=1+2500-1=2500 myrank=1 is=1x2500+0+1=2501 ie=2501+2500-1=5000 myrank=2 is=5001, ie=7500 myrank=3 is=7501, ie=10000

  5. MPI_REDUCE : 総和、最大値、最小値などを求める MPI_FINALIZE : MPI環境を終了する  MPIプログラム (3/3) SUM = 0.0 DO 20 I = is, ie SUM = SUM + A(I) 20 CONTINUE If( myrank .eq. 0) GSUM = 0 call MPI_REDUCE(SUM, GSUM, 1, MPI_REAL, MPI_SUM, 0, & MPI_COMM_WORLD, error) If( myrank .eq. 0) write(*,*) GSUM call mpi_finalize(error) stop end 各プロセスで実行

  6. MPI_REDUCE SUBROUTINE MPI_REDUCE(SENDBUF,RECVBUF,COUNT ,DATATYPE,OP,ROOT,COMM,IERROR) SENDBUF   送信する変数、配列名の先頭アドレスRECVBUF   受信する変数、配列名の先頭アドレスCOUNT    送信するデータの数DATATYPE  送信するデータの型OP        演算ROOT      受信元のプロセスのランクCOMM     コミュニケータ(通信グループの識別子)IERROR    戻り値(エラーコード)

  7. 実行結果 [kobayasi@tube sum]# mpirun -np 1 ./a.out 5.000500E+07 [kobayasi@tube sum]# mpirun -np 2 ./a.out 5.000500E+07 [kobayasi@tube sum]# mpirun -np 3 ./a.out 5.000500E+07 [kobayasi@tube sum]# mpirun -np 4 ./a.out 5.000500E+07 [kobayasi@tube sum]# mpirun -np 5 ./a.out 5.000500E+07 [kobayasi@tube sum]# mpirun -np 6 ./a.out 5.000500E+07 [kobayasi@tube sum]# mpirun -np 7 ./a.out 5.000500E+07 [kobayasi@tube sum]# mpirun -np 8 ./a.out 5.000500E+07 [kobayasi@tube sum]# mpirun -np 9 ./a.out 5.000500E+07 [kobayasi@tube sum]# mpirun -np 10 ./a.out 5.000500E+07

More Related