Blame src/mpi/romio/test/coll_perf.c

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
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
/* The file name is taken as a command-line argument. */
Packit Service c5cf8c
Packit Service c5cf8c
/* Measures the I/O bandwidth for writing/reading a 3D
Packit Service c5cf8c
   block-distributed array to a file corresponding to the global array
Packit Service c5cf8c
   in row-major (C) order.
Packit Service c5cf8c
   Note that the file access pattern is noncontiguous.
Packit Service c5cf8c
Packit Service c5cf8c
   Array size 128^3. For other array sizes, change array_of_gsizes below.*/
Packit Service c5cf8c
Packit Service c5cf8c
Packit Service c5cf8c
int main(int argc, char **argv)
Packit Service c5cf8c
{
Packit Service c5cf8c
    MPI_Datatype newtype;
Packit Service c5cf8c
    int i, ndims, array_of_gsizes[3], array_of_distribs[3];
Packit Service c5cf8c
    int order, nprocs, len, *buf, mynod;
Packit Service c5cf8c
    MPI_Count bufcount;
Packit Service c5cf8c
    int array_of_dargs[3], array_of_psizes[3];
Packit Service c5cf8c
    MPI_File fh;
Packit Service c5cf8c
    MPI_Status status;
Packit Service c5cf8c
    double stim, write_tim, new_write_tim, write_bw;
Packit Service c5cf8c
    double read_tim, new_read_tim, read_bw;
Packit Service c5cf8c
    char *filename;
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Init(&argc, &argv);
Packit Service c5cf8c
    MPI_Comm_rank(MPI_COMM_WORLD, &mynod);
Packit Service c5cf8c
    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
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 (!mynod) {
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: coll_perf -fname filename\n\n");
Packit Service c5cf8c
            MPI_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 + 1);
Packit Service c5cf8c
        strcpy(filename, *argv);
Packit Service c5cf8c
        MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
Packit Service c5cf8c
        MPI_Bcast(filename, len + 1, MPI_CHAR, 0, MPI_COMM_WORLD);
Packit Service c5cf8c
    } else {
Packit Service c5cf8c
        MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
Packit Service c5cf8c
        filename = (char *) malloc(len + 1);
Packit Service c5cf8c
        MPI_Bcast(filename, len + 1, MPI_CHAR, 0, MPI_COMM_WORLD);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
Packit Service c5cf8c
    ndims = 3;
Packit Service c5cf8c
    order = MPI_ORDER_C;
Packit Service c5cf8c
Packit Service c5cf8c
    array_of_gsizes[0] = 128 * 17;
Packit Service c5cf8c
    array_of_gsizes[1] = 128 * 9;
Packit Service c5cf8c
    array_of_gsizes[2] = 128 * 11;
Packit Service c5cf8c
Packit Service c5cf8c
    array_of_distribs[0] = MPI_DISTRIBUTE_BLOCK;
Packit Service c5cf8c
    array_of_distribs[1] = MPI_DISTRIBUTE_BLOCK;
Packit Service c5cf8c
    array_of_distribs[2] = MPI_DISTRIBUTE_BLOCK;
Packit Service c5cf8c
Packit Service c5cf8c
    array_of_dargs[0] = MPI_DISTRIBUTE_DFLT_DARG;
Packit Service c5cf8c
    array_of_dargs[1] = MPI_DISTRIBUTE_DFLT_DARG;
Packit Service c5cf8c
    array_of_dargs[2] = MPI_DISTRIBUTE_DFLT_DARG;
Packit Service c5cf8c
Packit Service c5cf8c
    for (i = 0; i < ndims; i++)
Packit Service c5cf8c
        array_of_psizes[i] = 0;
Packit Service c5cf8c
    MPI_Dims_create(nprocs, ndims, array_of_psizes);
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Type_create_darray(nprocs, mynod, ndims, array_of_gsizes,
Packit Service c5cf8c
                           array_of_distribs, array_of_dargs,
Packit Service c5cf8c
                           array_of_psizes, order, MPI_INT, &newtype);
Packit Service c5cf8c
    MPI_Type_commit(&newtype);
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Type_size_x(newtype, &bufcount);
Packit Service c5cf8c
    bufcount = bufcount / sizeof(int);
Packit Service c5cf8c
    buf = (int *) malloc(bufcount * sizeof(int));
Packit Service c5cf8c
Packit Service c5cf8c
/* to eliminate paging effects, do the operations once but don't time
Packit Service c5cf8c
   them */
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_CHECK(MPI_File_open(MPI_COMM_WORLD, filename,
Packit Service c5cf8c
                            MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh));
Packit Service c5cf8c
    MPI_CHECK(MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", MPI_INFO_NULL));
Packit Service c5cf8c
    MPI_CHECK(MPI_File_write_all(fh, buf, bufcount, MPI_INT, &status));
Packit Service c5cf8c
    MPI_CHECK(MPI_File_seek(fh, 0, MPI_SEEK_SET));
Packit Service c5cf8c
    MPI_CHECK(MPI_File_read_all(fh, buf, bufcount, MPI_INT, &status));
Packit Service c5cf8c
    MPI_CHECK(MPI_File_close(&fh));
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Barrier(MPI_COMM_WORLD);
Packit Service c5cf8c
/* now time write_all */
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_CHECK(MPI_File_open(MPI_COMM_WORLD, filename,
Packit Service c5cf8c
                            MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh));
Packit Service c5cf8c
    MPI_CHECK(MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", MPI_INFO_NULL));
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Barrier(MPI_COMM_WORLD);
Packit Service c5cf8c
    stim = MPI_Wtime();
Packit Service c5cf8c
    MPI_CHECK(MPI_File_write_all(fh, buf, bufcount, MPI_INT, &status));
Packit Service c5cf8c
    write_tim = MPI_Wtime() - stim;
Packit Service c5cf8c
    MPI_CHECK(MPI_File_close(&fh));
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Allreduce(&write_tim, &new_write_tim, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
Packit Service c5cf8c
Packit Service c5cf8c
    if (mynod == 0) {
Packit Service c5cf8c
        write_bw =
Packit Service c5cf8c
            (array_of_gsizes[0] * array_of_gsizes[1] * array_of_gsizes[2] * sizeof(int)) /
Packit Service c5cf8c
            (new_write_tim * 1024.0 * 1024.0);
Packit Service c5cf8c
        fprintf(stderr, "Global array size %d x %d x %d integers\n", array_of_gsizes[0],
Packit Service c5cf8c
                array_of_gsizes[1], array_of_gsizes[2]);
Packit Service c5cf8c
        fprintf(stderr,
Packit Service c5cf8c
                "Collective write time = %f sec, Collective write bandwidth = %f Mbytes/sec\n",
Packit Service c5cf8c
                new_write_tim, write_bw);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Barrier(MPI_COMM_WORLD);
Packit Service c5cf8c
/* now time read_all */
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_CHECK(MPI_File_open(MPI_COMM_WORLD, filename,
Packit Service c5cf8c
                            MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh));
Packit Service c5cf8c
    MPI_CHECK(MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", MPI_INFO_NULL));
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Barrier(MPI_COMM_WORLD);
Packit Service c5cf8c
    stim = MPI_Wtime();
Packit Service c5cf8c
    MPI_CHECK(MPI_File_read_all(fh, buf, bufcount, MPI_INT, &status));
Packit Service c5cf8c
    read_tim = MPI_Wtime() - stim;
Packit Service c5cf8c
    MPI_CHECK(MPI_File_close(&fh));
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Allreduce(&read_tim, &new_read_tim, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
Packit Service c5cf8c
Packit Service c5cf8c
    if (mynod == 0) {
Packit Service c5cf8c
        read_bw =
Packit Service c5cf8c
            (array_of_gsizes[0] * array_of_gsizes[1] * array_of_gsizes[2] * sizeof(int)) /
Packit Service c5cf8c
            (new_read_tim * 1024.0 * 1024.0);
Packit Service c5cf8c
        fprintf(stderr,
Packit Service c5cf8c
                "Collective read time = %f sec, Collective read bandwidth = %f Mbytes/sec\n",
Packit Service c5cf8c
                new_read_tim, read_bw);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Type_free(&newtype);
Packit Service c5cf8c
    free(buf);
Packit Service c5cf8c
    free(filename);
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Finalize();
Packit Service c5cf8c
    return 0;
Packit Service c5cf8c
}