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