MPI: Difference between revisions

Jump to navigation Jump to search
644 bytes added ,  5 years ago
m
Adding some Python (mpi4py) material
m (More Fortran updates)
m (Adding some Python (mpi4py) material)
Line 41: Line 41:


== MPI Programming Basics == <!--T:13-->
== MPI Programming Basics == <!--T:13-->
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, C++, Fortran, and Python, 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.
</translate>
</translate>
<tabs>
<tabs>
Line 84: Line 84:
   
   
  end program hello
  end program hello
}}
</tab>
<tab name="Python">
{{File
  |name=hello.py
  |lang="python"
  |contents=
print('Hello, world!')
}}
}}
</tab>
</tab>
Line 107: Line 115:
* C language wrapper: <tt>mpicc</tt>
* C language wrapper: <tt>mpicc</tt>
* Fortran: <tt>mpifort</tt> (recommended) or <tt>mpif90</tt>
* Fortran: <tt>mpifort</tt> (recommended) or <tt>mpif90</tt>
* C++: <tt>mpiCC</tt>
* C++: <tt>mpiCC</tt> or <tt>mpicxx</tt>


<!--T:19-->
<!--T:19-->
Line 243: Line 251:
  end program phello0
  end program phello0
}}
}}
</tab></tabs>
</tab>
<tab name="Python (mpi4py)">
{{File
  |name=phello0.py
  |lang="python"
  |contents=
from mpi4py import MPI
print('Hello, world!')
}}
</tab>
</tabs>
<translate>
<translate>
=== Rank and Size === <!--T:23-->
=== Rank and Size === <!--T:23-->
Line 381: Line 399:
   
   
  end program phello1
  end program phello1
}}
</tab>
<tab name="Python (mpi4py)">
{{File
  |name=phello1.py
  |lang="python"
  |contents=
from mpi4py import MPI
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
print('Hello from process %d of %d'%(rank, size))
}}
}}
</tab>
</tab>
Line 400: Line 432:
If you are using the Boost version, you should compile with:  
If you are using the Boost version, you should compile with:  
  [~]$ mpic++ --std=c++11 phello1.cpp -lboost_mpi-mt -lboost_serialization-mt -o phello1
  [~]$ mpic++ --std=c++11 phello1.cpp -lboost_mpi-mt -lboost_serialization-mt -o phello1
If you are using the Python version, you don't need to compile but can run with:
[~]$ mpirun -np 4 python phello1.py


=== Communication === <!--T:28-->
=== Communication === <!--T:28-->
cc_staff
153

edits

Navigation menu