File: mpi_spawn.c

package info (click to toggle)
eztrace 2.2.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,012 kB
  • sloc: ansic: 37,703; sh: 1,246; cpp: 1,181; perl: 910; makefile: 738; fortran: 327; f90: 320; python: 124
file content (43 lines) | stat: -rw-r--r-- 940 bytes parent folder | download | duplicates (12)
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
/* -*- c-file-style: "GNU" -*- */
/*
 * Copyright (C) CNRS, INRIA, Université Bordeaux 1, Télécom SudParis
 * See COPYING in top-level directory.
 */

#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>

#define NUM_SPAWNS 2

/* 'Compute' for a fixed duration */
void compute(unsigned usec) {
  double t1, t2;
  t1 = MPI_Wtime();
  do {
    t2 = MPI_Wtime();
  } while (((t2 - t1) * 1e6) < (double) usec);
}

int main(int argc, char *argv[]) {
  int np = NUM_SPAWNS;
  int errcodes[NUM_SPAWNS];
  MPI_Comm parentcomm, intercomm;

  MPI_Init(&argc, &argv);
  MPI_Comm_get_parent(&parentcomm);

  compute(100000);
  if (parentcomm == MPI_COMM_NULL) {
    MPI_Comm_spawn("./mpi_spawn", MPI_ARGV_NULL, np, MPI_INFO_NULL, 0,
                   MPI_COMM_WORLD, &intercomm, errcodes);
    printf("I'm the parent.\n");
    compute(1000000);
  } else {
    printf("I'm the spawned.\n");
  }

  fflush(stdout);
  MPI_Finalize();
  return 0;
}