-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmpi_hello.cpp
More file actions
44 lines (31 loc) · 1.04 KB
/
mpi_hello.cpp
File metadata and controls
44 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// This program shows off the basics of using MPI with C++
// By: Nick from CoffeeBeforeArch
#include <mpi.h>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
// Unique rank is assigned to each process in a communicator
int rank;
// Total number of ranks
int size;
// The machine we are on
char name[80];
// Length of the machine name
int length;
// Initializes the MPI execution environment
MPI_Init(&argc, &argv);
// Get this process' rank (process within a communicator)
// MPI_COMM_WORLD is the default communicator
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// Get the total number ranks in this communicator
MPI_Comm_size(MPI_COMM_WORLD, &size);
// Gets the name of the processor
// Implementation specific (may be gethostname, uname, or sysinfo)
MPI_Get_processor_name(name, &length);
// Print out for each rank
cout << "Hello, MPI! Rank: " << rank << " Total: " << size
<< " Machine: " << name << endl;
// Terminate MPI execution environment
MPI_Finalize();
return 0;
}