BaseCode.c 837 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
25
26
27
28
29
30
31
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>

int main(int argc, char* argv[]) {
  int rank, numP, numO;
  int rootBcast, order;
  double test = 0;
  int solution = 1;

  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &numP);

  MPI_Comm intercomm, intracomm;
  MPI_Comm_get_parent(&intercomm);
  if(intercomm == MPI_COMM_NULL) {
    numO = atoi(argv[1]);
    MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, numO, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &intercomm, MPI_ERRCODES_IGNORE);
    order = 0;
  } else { order = 1; }

  MPI_Intercomm_merge(intercomm, order, &intracomm);
  printf("TEST 1 P%02d/%d\n", rank, numP);
  MPI_Bcast(&test, 1, MPI_DOUBLE, 0, intracomm);
  if(solution) { MPI_Barrier(intercomm); }
  printf("TEST 2 P%02d/%d\n", rank, numP);

  MPI_Finalize();
  return 0;
}