TutorialsTutorials HomeMPI IntroductionIndexBasic Concepts Initialization Data Types Basic Send Basic Receive Broadcast Reduction Example
FullDocument
Related InfoMPI ResourcesIBM DocsProgramming GuideSubroutine Reference |
InitializationTo use the MPI library you must include header files which contain definitions and declarations that are needed by the MPI library routines. In Fortran 90 you can use the mpi module. The following line must appear at the top of any source code file that will make an MPI call. FortranINCLUDE 'mpif.h' USE mpi C/C++:#include "mpi.h" MPI_InitThe first MPI call must be MPI_INIT, which initializes the message passing routines, for example: Fortran:INTEGER:: ierr CALL MPI_INIT(ierr) where ierr is an integer which holds an error code when the call returns. NOTE: The value of ierr is really of little use since, by default, MPI aborts the program when it encounters an error. However, ierr must be included with MPI calls anyway. Cint MPI_Init( int *argc, char ***argv)
where MPI_FinalizeWhen you are finished with the message passing routines, you must close out the MPI routines. The command for doing this finalization is Fortran
CALL MPI_FINALIZE(ierr)
Cint MPI_Finalize(void) Inquiry routinesTwo other MPI calls are usually made soon after initialization. They are
ExampleThis example, hello.f90, available in $EXAMPLES/mpi/intro/hello demonstrates these calls. If we compile (you can type "make" to compile if you are using the example code) and run this code on franklin, we get franklin% ftn -o hello hello.f90 franklin% qsub -I -lmppwidth=4 franklin% cd $PBS_O_WORKDIR franklin% aprun -n 4 ./hello task_no is 3 of total 4 tasks task_no is 1 of total 4 tasks task_no is 0 of total 4 tasks task_no is 2 of total 4 tasks |
![]() |
Page last modified: Fri, 07 Mar 2008 00:10:40 GMT Page URL: http://www.nersc.gov/nusers/help/tutorials/mpi/intro/init.php Web contact: webmaster@nersc.gov Computing questions: consult@nersc.gov Privacy and Security Notice |
![]() |