|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit |
0848f5 |
* See COPYRIGHT in top-level directory.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
#include "mpi.h"
|
|
Packit |
0848f5 |
#include <stdio.h>
|
|
Packit |
0848f5 |
#include <string.h>
|
|
Packit |
0848f5 |
#include <stdlib.h>
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#define SIZE (65536)
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* This is the same as simple.c, but uses the PMPI versions of all
|
|
Packit |
0848f5 |
MPI functions in order to test the profiling interface. */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Each process writes to separate files and reads them back.
|
|
Packit |
0848f5 |
The file name is taken as a command-line argument, and the process rank
|
|
Packit |
0848f5 |
is appended to it. */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int main(int argc, char **argv)
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int *buf, i, rank, nints, len;
|
|
Packit |
0848f5 |
char *filename, *tmp;
|
|
Packit |
0848f5 |
int errs=0, toterrs;
|
|
Packit |
0848f5 |
MPI_File fh;
|
|
Packit |
0848f5 |
MPI_Status status;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
PMPI_Init(&argc,&argv);
|
|
Packit |
0848f5 |
PMPI_Comm_rank(MPI_COMM_WORLD, &rank;;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* process 0 takes the file name as a command-line argument and
|
|
Packit |
0848f5 |
broadcasts it to other processes */
|
|
Packit |
0848f5 |
if (!rank) {
|
|
Packit |
0848f5 |
i = 1;
|
|
Packit |
0848f5 |
while ((i < argc) && strcmp("-fname", *argv)) {
|
|
Packit |
0848f5 |
i++;
|
|
Packit |
0848f5 |
argv++;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (i >= argc) {
|
|
Packit |
0848f5 |
fprintf(stderr, "\n*# Usage: simple -fname filename\n\n");
|
|
Packit |
0848f5 |
PMPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
argv++;
|
|
Packit |
0848f5 |
len = strlen(*argv);
|
|
Packit |
0848f5 |
filename = (char *) malloc(len+10);
|
|
Packit |
0848f5 |
strcpy(filename, *argv);
|
|
Packit |
0848f5 |
PMPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
PMPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
PMPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
filename = (char *) malloc(len+10);
|
|
Packit |
0848f5 |
PMPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
buf = (int *) malloc(SIZE);
|
|
Packit |
0848f5 |
nints = SIZE/sizeof(int);
|
|
Packit |
0848f5 |
for (i=0; i
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* each process opens a separate file called filename.'myrank' */
|
|
Packit |
0848f5 |
tmp = (char *) malloc(len+10);
|
|
Packit |
0848f5 |
strcpy(tmp, filename);
|
|
Packit |
0848f5 |
sprintf(filename, "%s.%d", tmp, rank);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
PMPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE | MPI_MODE_RDWR,
|
|
Packit |
0848f5 |
MPI_INFO_NULL, &fh;;
|
|
Packit |
0848f5 |
PMPI_File_write(fh, buf, nints, MPI_INT, &status);
|
|
Packit |
0848f5 |
PMPI_File_close(&fh;;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* reopen the file and read the data back */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
for (i=0; i
|
|
Packit |
0848f5 |
PMPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE | MPI_MODE_RDWR,
|
|
Packit |
0848f5 |
MPI_INFO_NULL, &fh;;
|
|
Packit |
0848f5 |
PMPI_File_read(fh, buf, nints, MPI_INT, &status);
|
|
Packit |
0848f5 |
PMPI_File_close(&fh;;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* check if the data read is correct */
|
|
Packit |
0848f5 |
for (i=0; i
|
|
Packit |
0848f5 |
if (buf[i] != (rank*100000 + i)) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "Process %d: error, read %d, should be %d\n", rank, buf[i], rank*100000+i);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
|
|
Packit |
0848f5 |
if (rank == 0) {
|
|
Packit |
0848f5 |
if( toterrs > 0) {
|
|
Packit |
0848f5 |
fprintf( stderr, "Found %d errors\n", toterrs );
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
fprintf( stdout, " No Errors\n" );
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
free(buf);
|
|
Packit |
0848f5 |
free(filename);
|
|
Packit |
0848f5 |
free(tmp);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
PMPI_Finalize();
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|