BaseCode.c 586 Bytes
Newer Older
iker_martin's avatar
iker_martin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>

#define FIRST 0
#define SECOND 1

int main(int argc, char* argv[]) {
    MPI_Init(&argc, &argv);
    
    MPI_Comm spawn, new_comm;
    MPI_Comm_get_parent(&spawn);
    if(spawn == MPI_COMM_NULL) {
	int num_c = atoi(argv[1]);
        MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, num_c, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &spawn, MPI_ERRCODES_IGNORE);
        MPI_Intercomm_merge(spawn, FIRST,  &new_comm);
	
    } else {
        MPI_Intercomm_merge(spawn, SECOND, &new_comm);
	MPI_Barrier(MPI_COMM_WORLD);
    }

    MPI_Finalize(); 
}