root/examples/dtrace/mpicommleak.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main
  2. allocate_comms
  3. deallocate_comms

   1 /*
   2  * Copyright (c) 2006      Sun Microsystems, Inc.  All rights reserved.
   3  *                         Use is subject to license terms.
   4  * $COPYRIGHT$
   5  *
   6  * Additional copyrights may follow
   7  *
   8  * $HEADER$
   9  */
  10 
  11 #include <errno.h>
  12 #include <stdio.h>
  13 #include <stdlib.h>
  14 #include <string.h>
  15 #include <netdb.h>
  16 #include <unistd.h>
  17 
  18 #include <mpi.h>
  19 
  20 #define ITERATIONS 1000000
  21 
  22 static void allocate_comms(void);
  23 static void deallocate_comms(void);
  24 static MPI_Comm communicator_a, communicator_b, communicator_c;
  25 
  26 int
  27 main(int argc, char *argv[])
  28 {
  29     int         rank;                         /* COMM_WORLD rank of process */
  30     int         np;                           /* number of processes in job */
  31     int         i;
  32     int         unslept;
  33 
  34     MPI_Init(&argc, &argv);
  35     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  36     MPI_Comm_size(MPI_COMM_WORLD, &np);
  37 
  38     for (i=0; i < ITERATIONS; i++) {
  39         /* allocate our communicators */
  40         allocate_comms();
  41 
  42         /* simulate doing work */
  43         unslept = sleep(5);
  44 
  45         /* deallocate communicators forgetting one of the communicators */
  46         deallocate_comms();
  47     }
  48     MPI_Finalize();
  49     return 0;
  50 }
  51 
  52 void allocate_comms(void) {
  53     MPI_Comm_dup(MPI_COMM_WORLD, &communicator_a);
  54     MPI_Comm_dup(MPI_COMM_WORLD, &communicator_b);
  55     MPI_Comm_dup(MPI_COMM_WORLD, &communicator_c);
  56 }
  57 
  58 void deallocate_comms(void) {
  59     MPI_Comm_free(&communicator_a);
  60     MPI_Comm_free(&communicator_c);
  61 }

/* [<][>][^][v][top][bottom][index][help] */