168
edits
(Created page with "== MPI Hello World == Many parallel jobs are using MPI at the lowest level to manage parallel compute resources. This is a 'Hello World' program that will test the operation...") |
|||
This is a 'Hello World' program that will test the operation of sending jobs to remote workers.
<nowiki>
/*
* Sample MPI "hello world" application in C
return 0;
}
</nowiki>
create a folder and save this file as helloworld_mpi.c
You can compile this program with
mpicc -g helloworld_mpi.c -o helloworld_mpi
You now have an executable called helloworld_mpi
You can run the command with
mpirun ./helloworld_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.
Now, to run your mpi program on the cluster, you will need to create a hostfile.
First, lets create a simple hostfile that just runs four processes on the local machine
<nowiki>
localhost slots=4 max_slots=8
</nowiki>
Put that line in a file called 'localhost'.
Now run your program with that hostfile, using
mpirun --hostfile localhost ./helloworld_mpi
<
Hello, world, I am 2 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 0 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>
|