/*
 * example for MPI-2 I/O :
 * content of one file is distributed to everybody
 *
 * for simplicity: File contains 100 int's
 *
 */

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

#define   FILE   "IN1"
#define   SIZE   100


void check(int *a) {
  int   myid;
  int   i;

  MPI_Comm_rank(MPI_COMM_WORLD, &myid);

  for (i=0;i<SIZE;i++) {
    if (a[i] != 100 - i) {
      printf("Task %d: error in data: a(%d) = %d, should be %d\n", 
	     myid, i, a[i], 100-i);
      return;
    }
  }

  printf("Task %d: check ok\n", myid);
  return;
}

void main(int argc, char *argv[]) {
  MPI_File       fh;
  MPI_Status     status;
  int            a[SIZE];

  MPI_Init(&argc, &argv);

  MPI_File_open(MPI_COMM_WORLD, FILE, MPI_MODE_RDONLY, MPI_INFO_NULL, &fh); 
  MPI_File_set_view(fh, 0, MPI_INT, MPI_INT, "native", MPI_INFO_NULL); 

  MPI_File_read(fh, a, SIZE, MPI_INT, &status); 
  
  check(a);

  MPI_File_close(&fh);
  MPI_Finalize();
}