Difference between revisions of "MPI Hello World"

Jump to navigation Jump to search
402 bytes removed ,  13:06, 24 September 2022
</nowiki>
 
create a folder and save this file as helloworld_mpihello_mpi.c
 
You can compile this program with
 
mpicc -g helloworld_mpihello_mpi.c -o helloworld_mpihello_mpi
 
You now have an executable called helloworld_mpihello_mpi
 
You can run the command with
mpirun ./helloworld_mpihello_mpi
 
With no other arguments, mpirun will run all of the tasks on the local machine, usually one for each CPU core. You should see a hello world from each process, on each cpu core.
Put that line in a file called 'localhost'.
Now run your program with that hostfile, using
mpirun --hostfile localhost ./helloworld_mpihello_mpi
 
<nowiki>
Hello, world, I am 20 of 4, (Open MPI v4.0.3, package: Debian OpenMPI, ident: 4.0.3, repo rev: v4.0.3, Mar 03, 2020, 87)
Hello, world, I am 02 of 4, (Open MPI v4.0.3, package: Debian OpenMPI, ident: 4.0.3, repo rev: v4.0.3, Mar 03, 2020, 87)
Hello, world, I am 1 of 4, (Open MPI v4.0.3, package: Debian OpenMPI, ident: 4.0.3, repo rev: v4.0.3, Mar 03, 2020, 87)
Hello, world, I am 3 of 4, (Open MPI v4.0.3, package: Debian OpenMPI, ident: 4.0.3, repo rev: v4.0.3, Mar 03, 2020, 87)
</nowiki>

Navigation menu