DAWNING 乡 曙光 DAWNING 丫:运行我们的MP程序! 科拔计算未来 [dair@node01 -S mpicc-o hello hello.c [dair@nodel -S/ hello [O] Aborting program Could not create p4 procgroup Possible missing fileor program started without mpirun [dair@node01 -IS mpirun -roy hello Hello world Hello world! Hello world Hello World 计算机打印字符 [dair@node01 -I$ 我们输入的命令 2021年1月 MP|并行程序设计 18/217
2021年1月 MPI并行程序设计 18/217 :运行我们的MPI程序! • [dair@node01 ~]$ mpicc -o hello hello.c • [dair@node01 ~]$ ./hello () [0] Aborting program ! Could not create p4 procgroup. Possible missing fileor program started without mpirun. • [dair@node01 ~]$ mpirun -np 4 hello () Hello World! Hello World! Hello World! Hello World! • [dair@node01 ~]$ 计算机打印字符 我们输入的命令
DAWNING 曙光 DAWNING : Hello是如何被执行的? 技计算未来 SPMD: Single Program Multiple Data(SPMD # #include"mpi.h #include <stdio. h> #include"mpi.h #include"mpi.h main #include "mpi. h int argc, #include <stdio. h> char'argvU) MPl_Init( &argc, &argv ) I int arg printf("Hello, world! In") I char'argvll MPl_Finalize() MPl_Init(&argc, &argv ) printf("Hello, world! In") MPl_Finalized Hello World! Hello world Hello world! Hello world 2021年1月 MP|并行程序设计 19/217
2021年1月 MPI并行程序设计 19/217 :Hello是如何被执行的? • SPMD: Single Program Multiple Data(SPMD) :::: #include "mpi.h" #include <stdio.h> main( int argc, char *argv[] ) { MPI_Init( &argc, &argv ); printf( "Hello, world!\n" ); MPI_Finalize(); } #include "mpi.h" #include <stdio.h> main( int argc, char *argv[] ) { MPI_Init( &argc, &argv ); printf( "Hello, world!\n" ); MPI_Finalize(); } #include "mpi.h" #include <stdio.h> main( int argc, char *argv[] ) { MPI_Init( &argc, &argv ); printf( "Hello, world!\n" ); MPI_Finalize(); } #include "mpi.h" #include <stdio.h> main( int argc, char *argv[] ) { MPI_Init( &argc, &argv ); printf( "Hello, world!\n" ); MPI_Finalize(); } Hello World! Hello World! Hello World! Hello World! #include "mpi.h" #include <stdio.h> main( int argc, char *argv[] ) { MPI_Init( &argc, &argv ); printf( "Hello, world!\n" ); MPI_Finalize(); }
DAWNING 乡 曙光 DAWNING 科拔计算未来 :开始写MP并行程序 在写MPl程序时,我们常需要知道以下两个 问题的答案: 一任务由多少个进程来进行并行计算? 我是哪一个进程? 2021年1月 MP|并行程序设计 20217
2021年1月 MPI并行程序设计 20/217 :开始写MPI并行程序 • 在写MPI程序时,我们常需要知道以下两个 问题的答案: – 任务由多少个进程来进行并行计算? – 我是哪一个进程?
DAWNING 乡 曙光 DAWNING 科拔计算未来 隅:开始写MP并行程序 MP|提供了下列函数来回答这些问题: 用 MPI Comm size获得进程个数p int MPl Comm size(MPI Comm comm, int *size) 用 MPI Comm rank获得进程的一个叫rank的值,该 rank值为0到p1间的整数,相当于进程的|D int MPI Comm rank (MPl Comm comm, int *rank) 2021年1月 MP|并行程序设计 21/217
2021年1月 MPI并行程序设计 21/217 :开始写MPI并行程序 • MPI 提供了下列函数来回答这些问题: – 用MPI_Comm_size 获得进程个数 p int MPI_Comm_size(MPI_Comm comm, int *size); – 用MPI_Comm_rank 获得进程的一个叫rank的值,该 rank值为0到p-1间的整数,相当于进程的ID int MPI_Comm_rank(MPI_Comm comm, int *rank);
DAWNING 乡 曙光 DAWNING 更新的He| o World(c) 科拔计算未来 include <stdio. h> include " mpi. h main( int argc, char *argv[] { int myid, numprocsi MPI Init( &argc, &argv )i MPI Comm rank( MPI COMM WORLD, &myid)i MPI Comm size( MPI COMM WORLD, &numprocs )i printf( I am d of %d\n", myid, numprocs )i MPI Finalize 2021年1月 MP|并行程序设计 221217
2021年1月 MPI并行程序设计 22/217 更新的Hello World(c) #include <stdio.h> #include "mpi.h" main( int argc, char *argv[] ) { int myid, numprocs; MPI_Init( &argc, &argv ); MPI_Comm_rank( MPI_COMM_WORLD, &myid ); MPI_Comm_size( MPI_COMM_WORLD, &numprocs ); printf(“I am %d of %d\n", myid, numprocs ); MPI_Finalize(); }