Bureaucrats, cc_docs_admin, cc_staff, rsnt_translations
2,837
edits
No edit summary |
|||
Line 30: | Line 30: | ||
This tutorial will present the development of an MPI code in C and Fortran, but the concepts apply to any language for which MPI bindings exist. For simplicity our goal will be to parallelize the venerable "Hello, World!" program, which appears below for reference. | This tutorial will present the development of an MPI code in C and Fortran, but the concepts apply to any language for which MPI bindings exist. For simplicity our goal will be to parallelize the venerable "Hello, World!" program, which appears below for reference. | ||
<tabs> | |||
<tab name="C"> | |||
{{File | |||
| | |name=example0.c | ||
| | |lang="c" | ||
|contents= | |||
#include <stdio.h> | #include <stdio.h> | ||
Line 43: | Line 44: | ||
return(0); | return(0); | ||
} | } | ||
</ | }} | ||
| | </tab> | ||
<tab name="Fortran"> | |||
{{File | |||
|name=example0.f90 | |||
|lang="fortran" | |||
|contents= | |||
program hello | program hello | ||
Line 50: | Line 56: | ||
end program hello | end program hello | ||
</ | }} | ||
</tab> | |||
</tabs> | |||
Compiling and running the program looks something like this: | Compiling and running the program looks something like this: | ||
Line 106: | Line 113: | ||
Let's now modify our "Hello, world!" program accordingly. | Let's now modify our "Hello, world!" program accordingly. | ||
<tabs> | |||
<tab name="C Code"> | |||
{{File | |||
| | |name=example1.c | ||
| | |lang="c" | ||
|contents= | |||
#include <stdio.h> | |||
#include <mpi.h> | |||
int main(int argc, char *argv[]) | |||
{ | |||
MPI_Init(&argc, &argv); | |||
printf("Hello, world!\n"); | |||
MPI_Finalize(); | |||
return(0); | |||
} | |||
</ | }} | ||
| | </tab> | ||
<tab name="Fortran"> | |||
{{File | |||
|name=example1.f90 | |||
|lang="fortran" | |||
|contents= | |||
program phello0 | |||
include "mpif.h" | include "mpif.h" | ||
Line 136: | Line 149: | ||
end program phello0 | end program phello0 | ||
</ | }} | ||
</tab> | |||
</tabs> | |||
=== Rank and Size === | === Rank and Size === | ||
Line 167: | Line 181: | ||
! style="background:#ECCF98;" | '''FORTRAN CODE''': <tt>phello1.f</tt> | ! style="background:#ECCF98;" | '''FORTRAN CODE''': <tt>phello1.f</tt> | ||
|-valign="top" | |-valign="top" | ||
| | | | ||
{{File | |||
|name=example1.c | |||
|lang="C" | |||
|contents= | |||
#include <stdio.h> | #include <stdio.h> | ||
#include <mpi.h> | #include <mpi.h> | ||
Line 185: | Line 203: | ||
return(0); | return(0); | ||
} | } | ||
}} | |||
|<source lang="fortran"> | |<source lang="fortran"> | ||
program phello1 | program phello1 |