ScaLAPACK  2.0.2
ScaLAPACK: Scalable Linear Algebra PACKage
cmpi_sane.c File Reference
#include <stdio.h>
#include "mpi.h"
Include dependency graph for cmpi_sane.c:

Go to the source code of this file.

Defines

#define WASTE_SIZE   100
#define NPROC   4

Functions/Subroutines

 main (int narg, char **args)

Define Documentation

#define NPROC   4

Definition at line 8 of file cmpi_sane.c.

#define WASTE_SIZE   100

Definition at line 7 of file cmpi_sane.c.


Function/Subroutine Documentation

main ( int  narg,
char **  args 
)

Definition at line 9 of file cmpi_sane.c.

{
   int i, Iam, Np;
   int irank[NPROC];
   double WasteOfSpace[WASTE_SIZE];
   MPI_Comm  mcom;
   MPI_Group wgrp, mgrp;
   MPI_Status stat;

   MPI_Init(&narg, &args);
   MPI_Comm_size(MPI_COMM_WORLD, &Np);
   if (Np < NPROC)
   {
      fprintf(stderr, "Not enough processes to run sanity check; need %d, but I've only got %d\n", NPROC, Np);
      MPI_Abort(MPI_COMM_WORLD, -1);
   }

   for (i=0; i != WASTE_SIZE; i++) WasteOfSpace[i] = 0.0;  /* page in Waste */
/*
 * Form context with NPROC members
 */
   for (i=0; i != NPROC; i++) irank[i] = i;
   MPI_Comm_group(MPI_COMM_WORLD, &wgrp);
   MPI_Group_incl(wgrp, NPROC, irank, &mgrp);
   MPI_Comm_create(MPI_COMM_WORLD, mgrp, &mcom);
   MPI_Group_free(&mgrp);
/*
 * Everyone in new communicator sends a message to his neighbor
 */
   if (mcom != MPI_COMM_NULL)
   {
      MPI_Comm_rank(mcom, &Iam);
/*
 *    Odd nodes receive first, so we don't hang if MPI_Send is globally blocking
 */
      if (Iam % 2)
      {
         MPI_Recv(&i, 1, MPI_INT, (NPROC+Iam-1)%NPROC, 0, mcom, &stat);
         MPI_Send(&Iam, 1, MPI_INT, (Iam+1)%NPROC, 0, mcom);
      }
      else
      {
         MPI_Send(&Iam, 1, MPI_INT, (Iam+1)%NPROC, 0, mcom);
         MPI_Recv(&i, 1, MPI_INT, (NPROC+Iam-1)%NPROC, 0, mcom, &stat);
      }
/*
 *    Make sure we've received the right information
 */
      if (i != (NPROC+Iam-1)%NPROC)
      {
         fprintf(stderr, "Communication does not seem to work properly!!\n");
         MPI_Abort(MPI_COMM_WORLD, -1);
      }
   }
   fprintf(stdout, "%d: C MPI sanity test passed\n", Iam);
   MPI_Finalize();
   exit(0);
}