MPI: Difference between revisions

Jump to navigation Jump to search
162 bytes removed ,  7 years ago
no edit summary
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.


{| border="0" cellpadding="5" cellspacing="0" align="center"
<tabs>
! style="background:#8AA8E5;" | ''C CODE'': <tt>hello.c</tt>
<tab name="C">
! style="background:#ECCF98;" | ''FORTRAN'' <tt>CODE: hello.f</tt>
{{File
|-valign="top"
  |name=example0.c
|<source lang="c">
  |lang="c"
  |contents=
  #include <stdio.h>
  #include <stdio.h>
   
   
Line 43: Line 44:
     return(0);
     return(0);
  }
  }
</source>
}}
|<source lang="fortran">
</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
</source>
}}
|}
</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.


{| border="0" cellpadding="5" cellspacing="0" align="center"
<tabs>
! style="background:#8AA8E5;" | ''C CODE'': <tt>phello0.c</tt>
<tab name="C Code">
! style="background:#ECCF98;" | ''FORTRAN CODE'': <tt>phello0.f</tt>
{{File
|-valign="top"
  |name=example1.c
|<source lang="c">
  |lang="c"
#include <stdio.h>
  |contents=
#include <mpi.h>
#include <stdio.h>
#include <mpi.h>
   
   
int main(int argc, char *argv[])
int main(int argc, char *argv[])
{
{
    MPI_Init(&argc, &argv);
    MPI_Init(&argc, &argv);
   
   
    printf("Hello, world!\n");
    printf("Hello, world!\n");
   
   
    MPI_Finalize();
    MPI_Finalize();
    return(0);
    return(0);
}
}
</source>
}}
|<source lang="fortran">
</tab>
program phello0
<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
</source>
}}
|}
</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"
|<source lang="c">
|
{{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>
}}
|<source lang="fortran">
|<source lang="fortran">
  program phello1
  program phello1
Bureaucrats, cc_docs_admin, cc_staff, rsnt_translations
2,837

edits

Navigation menu