root/ompi/mca/io/romio321/romio/test/status.c

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

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
   2 /*  
   3  *  (C) 2001 by Argonne National Laboratory.
   4  *      See COPYRIGHT in top-level directory.
   5  */
   6 #include "mpi.h"
   7 #include <stdio.h>
   8 #include <string.h>
   9 #include <stdlib.h>
  10 
  11 #define SIZE (65536)
  12 
  13 /* Checks if the status objects is filled correctly by I/O functions */ 
  14 
  15 int main(int argc, char **argv)
  16 {
  17     int *buf, i, rank, nints, len, count, elements;
  18     char *filename, *tmp;
  19     int errs=0, toterrs;
  20     MPI_File fh;
  21     MPI_Status status;
  22 
  23     MPI_Init(&argc,&argv);
  24     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  25 
  26 /* process 0 takes the file name as a command-line argument and 
  27    broadcasts it to other processes */
  28     if (!rank) {
  29         i = 1;
  30         while ((i < argc) && strcmp("-fname", *argv)) {
  31             i++;
  32             argv++;
  33         }
  34         if (i >= argc) {
  35             fprintf(stderr, "\n*#  Usage: simple -fname filename\n\n");
  36             MPI_Abort(MPI_COMM_WORLD, 1);
  37         }
  38         argv++;
  39         len = strlen(*argv);
  40         filename = (char *) malloc(len+10);
  41         strcpy(filename, *argv);
  42         MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
  43         MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
  44     }
  45     else {
  46         MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
  47         filename = (char *) malloc(len+10);
  48         MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
  49     }
  50     
  51     buf = (int *) malloc(SIZE);
  52     nints = SIZE/sizeof(int);
  53 
  54     /* each process opens a separate file called filename.'myrank' */
  55     tmp = (char *) malloc(len+10);
  56     strcpy(tmp, filename);
  57     sprintf(filename, "%s.%d", tmp, rank);
  58 
  59     MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE | MPI_MODE_RDWR,
  60                    MPI_INFO_NULL, &fh);
  61     MPI_File_write(fh, buf, nints, MPI_INT, &status);
  62 
  63     MPI_Get_count(&status, MPI_INT, &count);
  64     MPI_Get_elements(&status, MPI_INT, &elements);
  65     if (!rank) {
  66         if (count != nints) {
  67             errs++;
  68             printf("count = %d, should be %d\n", count, nints);
  69         }
  70         if (elements != nints) {
  71             errs++;
  72             printf("elements = %d, should be %d\n", elements, nints);
  73         }
  74     }
  75 
  76     MPI_File_close(&fh);
  77 
  78     MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
  79     if (rank == 0) {
  80         if( toterrs > 0) {
  81             fprintf( stderr, "Found %d errors\n", toterrs );
  82         }
  83         else {
  84             fprintf( stdout, " No Errors\n" );
  85         }
  86     }
  87     free(buf);
  88     free(filename);
  89     free(tmp);
  90 
  91     MPI_Finalize();
  92     return 0; 
  93 }

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