-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathL10Ex3.cpp
32 lines (25 loc) · 1000 Bytes
/
L10Ex3.cpp
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
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv[] )
{
int world_size, rank, globalrank, namelen, flag, universe_size, *universe_sizep;
char processor_name[MPI_MAX_PROCESSOR_NAME];
MPI_Comm family_comm, allcomm;
MPI_Info hostinfo;
char* host = (char*)"host";
MPI_Init(&argc, &argv);
MPI_Get_processor_name(processor_name, &namelen);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Info_create(&hostinfo);
MPI_Info_set(hostinfo, host, "compute-0-0,compute-0-3");
int num_to_spawn = 4;
printf("Spawning %d processes\n", num_to_spawn);
MPI_Comm_spawn("./L10Ex3_child.exe", MPI_ARGV_NULL, num_to_spawn, hostinfo, 0, MPI_COMM_SELF, &family_comm, MPI_ERRCODES_IGNORE);
MPI_Intercomm_merge(family_comm, 1, &allcomm);
MPI_Comm_rank(allcomm, &globalrank);
printf("[PARENT %d/%d on %s]", rank, globalrank, processor_name);
MPI_Finalize();
return 0;
}