mpirun及MPI_Init
Hello是個mpi-aware的平行程式,當在單一主機上執行指令:
mpirun -np 4 ./Hello
會出現下現訊息:
It seems that [at least] one of the processes that was started with mpirun did not invoke MPI_INIT before quitting (it is possible that more than one process did not invoke MPI_INIT -- mpirun was only notified of the first one, which was on node n0).
亦即MPI_Init只會被head-node來invoke一次,之後就由head-node來派送task,到不同的worker-nodes上。
mpirun can *only* be used with MPI programs (i.e., programs that invoke MPI_INIT and MPI_FINALIZE). You can use the "lamexec" program to run non-MPI programs over the lambooted nodes.
如果使用lamexec來執行mpi-aware的程式,就沒有問題。
MPI@Ubuntu-5.10
在Ubuntu-5.10安裝了libmpich1.0, libmpich1.0-dev(含有檔頭mpi.h),以及mpich-bin(含有mpirun),mpi-doc(含有wegpages, Shared Memory的pdf檔, manpages...等等)
現在要學的MPICH,己經到了mpich2
Assignment#1:
#include#include "mpi.h" int main(int argc, char *argv[]) { int rank, size; MPI_Init( &argc, &argv ); MPI_Comm_size( MPI_COMM_WORLD, &size ); MPI_Comm_rank( MPI_COMM_WORLD, &rank ); printf( "Hello world from process %d of %d\n", rank, size ); MPI_Finalize(); return 0; }
Makefile:
ALL: Hello Hello: Hello.c mpicc -o helloworld helloworld.c clean: /bin/rm -f helloworld *.o
主要是先要去瞭解一些API的用法:
- MPI_Init:
- MPI_Comm_rank:
- MPI_Bcast:
- MPI_Finalize: