Blame test/mpi/io/i_noncontig_coll2.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *  (C) 2014 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
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
/* tests noncontiguous reads/writes using nonblocking collective I/O */
Packit 0848f5
Packit 0848f5
/* this test is almost exactly like i_noncontig_coll.c with the following changes:
Packit 0848f5
 *
Packit 0848f5
 * . generalized file writing/reading to handle arbitrary number of processors
Packit 0848f5
 * . provides the "cb_config_list" hint with several permutations of the
Packit 0848f5
 *   avaliable processors.
Packit 0848f5
 *   [ makes use of code copied from ROMIO's ADIO code to collect the names of
Packit 0848f5
 *   the processors ]
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
/* we are going to muck with this later to make it evenly divisible by however many compute nodes we have */
Packit 0848f5
#define STARTING_SIZE 5000
Packit 0848f5
Packit 0848f5
int test_file(char *filename, int mynod, int nprocs, char *cb_hosts, const char *msg, int verbose);
Packit 0848f5
Packit 0848f5
#define ADIOI_Free free
Packit 0848f5
#define ADIOI_Malloc malloc
Packit 0848f5
#define FPRINTF fprintf
Packit 0848f5
/* I have no idea what the "D" stands for; it's how things are done in adio.h
Packit 0848f5
 */
Packit 0848f5
struct ADIO_cb_name_arrayD {
Packit 0848f5
    int refct;
Packit 0848f5
    int namect;
Packit 0848f5
    char **names;
Packit 0848f5
};
Packit 0848f5
typedef struct ADIO_cb_name_arrayD *ADIO_cb_name_array;
Packit 0848f5
Packit 0848f5
void handle_error(int errcode, const char *str);
Packit 0848f5
int cb_gather_name_array(MPI_Comm comm, ADIO_cb_name_array * arrayp);
Packit 0848f5
void default_str(int mynod, int len, ADIO_cb_name_array array, char *dest);
Packit 0848f5
void reverse_str(int mynod, int len, ADIO_cb_name_array array, char *dest);
Packit 0848f5
void reverse_alternating_str(int mynod, int len, ADIO_cb_name_array array, char *dest);
Packit 0848f5
void simple_shuffle_str(int mynod, int len, ADIO_cb_name_array array, char *dest);
Packit 0848f5
Packit 0848f5
Packit 0848f5
void handle_error(int errcode, const char *str)
Packit 0848f5
{
Packit 0848f5
    char msg[MPI_MAX_ERROR_STRING];
Packit 0848f5
    int resultlen;
Packit 0848f5
    MPI_Error_string(errcode, msg, &resultlen);
Packit 0848f5
    fprintf(stderr, "%s: %s\n", str, msg);
Packit 0848f5
    MPI_Abort(MPI_COMM_WORLD, 1);
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
Packit 0848f5
/* cb_gather_name_array() - gather a list of processor names from all processes
Packit 0848f5
 *                          in a communicator and store them on rank 0.
Packit 0848f5
 *
Packit 0848f5
 * This is a collective call on the communicator(s) passed in.
Packit 0848f5
 *
Packit 0848f5
 * Obtains a rank-ordered list of processor names from the processes in
Packit 0848f5
 * "dupcomm".
Packit 0848f5
 *
Packit 0848f5
 * Returns 0 on success, -1 on failure.
Packit 0848f5
 *
Packit 0848f5
 * NOTE: Needs some work to cleanly handle out of memory cases!
Packit 0848f5
 */
Packit 0848f5
int cb_gather_name_array(MPI_Comm comm, ADIO_cb_name_array * arrayp)
Packit 0848f5
{
Packit 0848f5
    /* this is copied from ROMIO, but since this test is for correctness,
Packit 0848f5
     * not performance, note that we have removed the parts where ROMIO
Packit 0848f5
     * uses a keyval to cache the name array.  We'll just rebuild it if we
Packit 0848f5
     * need to */
Packit 0848f5
Packit 0848f5
    char my_procname[MPI_MAX_PROCESSOR_NAME], **procname = 0;
Packit 0848f5
    int *procname_len = NULL, my_procname_len, *disp = NULL, i;
Packit 0848f5
    int commsize, commrank;
Packit 0848f5
    ADIO_cb_name_array array = NULL;
Packit 0848f5
Packit 0848f5
    MPI_Comm_size(comm, &commsize);
Packit 0848f5
    MPI_Comm_rank(comm, &commrank);
Packit 0848f5
Packit 0848f5
    MPI_Get_processor_name(my_procname, &my_procname_len);
Packit 0848f5
Packit 0848f5
    /* allocate space for everything */
Packit 0848f5
    array = (ADIO_cb_name_array) malloc(sizeof(*array));
Packit 0848f5
    if (array == NULL) {
Packit 0848f5
        return -1;
Packit 0848f5
    }
Packit 0848f5
    array->refct = 1;
Packit 0848f5
Packit 0848f5
    if (commrank == 0) {
Packit 0848f5
        /* process 0 keeps the real list */
Packit 0848f5
        array->namect = commsize;
Packit 0848f5
Packit 0848f5
        array->names = (char **) ADIOI_Malloc(sizeof(char *) * commsize);
Packit 0848f5
        if (array->names == NULL) {
Packit 0848f5
            return -1;
Packit 0848f5
        }
Packit 0848f5
        procname = array->names;        /* simpler to read */
Packit 0848f5
Packit 0848f5
        procname_len = (int *) ADIOI_Malloc(commsize * sizeof(int));
Packit 0848f5
        if (procname_len == NULL) {
Packit 0848f5
            return -1;
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
    else {
Packit 0848f5
        /* everyone else just keeps an empty list as a placeholder */
Packit 0848f5
        array->namect = 0;
Packit 0848f5
        array->names = NULL;
Packit 0848f5
    }
Packit 0848f5
    /* gather lengths first */
Packit 0848f5
    MPI_Gather(&my_procname_len, 1, MPI_INT, procname_len, 1, MPI_INT, 0, comm);
Packit 0848f5
Packit 0848f5
    if (commrank == 0) {
Packit 0848f5
#ifdef CB_CONFIG_LIST_DEBUG
Packit 0848f5
        for (i = 0; i < commsize; i++) {
Packit 0848f5
            FPRINTF(stderr, "len[%d] = %d\n", i, procname_len[i]);
Packit 0848f5
        }
Packit 0848f5
#endif
Packit 0848f5
Packit 0848f5
        for (i = 0; i < commsize; i++) {
Packit 0848f5
            /* add one to the lengths because we need to count the
Packit 0848f5
             * terminator, and we are going to use this list of lengths
Packit 0848f5
             * again in the gatherv.
Packit 0848f5
             */
Packit 0848f5
            procname_len[i]++;
Packit 0848f5
            procname[i] = malloc(procname_len[i]);
Packit 0848f5
            if (procname[i] == NULL) {
Packit 0848f5
                return -1;
Packit 0848f5
            }
Packit 0848f5
        }
Packit 0848f5
Packit 0848f5
        /* create our list of displacements for the gatherv.  we're going
Packit 0848f5
         * to do everything relative to the start of the region allocated
Packit 0848f5
         * for procname[0]
Packit 0848f5
         *
Packit 0848f5
         * I suppose it is theoretically possible that the distance between
Packit 0848f5
         * malloc'd regions could be more than will fit in an int.  We don't
Packit 0848f5
         * cover that case.
Packit 0848f5
         */
Packit 0848f5
        disp = malloc(commsize * sizeof(int));
Packit 0848f5
        disp[0] = 0;
Packit 0848f5
        for (i = 1; i < commsize; i++) {
Packit 0848f5
            disp[i] = (int) (procname[i] - procname[0]);
Packit 0848f5
        }
Packit 0848f5
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    /* now gather strings */
Packit 0848f5
    if (commrank == 0) {
Packit 0848f5
        MPI_Gatherv(my_procname, my_procname_len + 1, MPI_CHAR,
Packit 0848f5
                    procname[0], procname_len, disp, MPI_CHAR, 0, comm);
Packit 0848f5
    }
Packit 0848f5
    else {
Packit 0848f5
        /* if we didn't do this, we would need to allocate procname[]
Packit 0848f5
         * on all processes...which seems a little silly.
Packit 0848f5
         */
Packit 0848f5
        MPI_Gatherv(my_procname, my_procname_len + 1, MPI_CHAR,
Packit 0848f5
                    NULL, NULL, NULL, MPI_CHAR, 0, comm);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    if (commrank == 0) {
Packit 0848f5
        /* no longer need the displacements or lengths */
Packit 0848f5
        free(disp);
Packit 0848f5
        free(procname_len);
Packit 0848f5
Packit 0848f5
#ifdef CB_CONFIG_LIST_DEBUG
Packit 0848f5
        for (i = 0; i < commsize; i++) {
Packit 0848f5
            fprintf(stderr, "name[%d] = %s\n", i, procname[i]);
Packit 0848f5
        }
Packit 0848f5
#endif
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    *arrayp = array;
Packit 0848f5
    return 0;
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
void default_str(int mynod, int len, ADIO_cb_name_array array, char *dest)
Packit 0848f5
{
Packit 0848f5
    char *ptr;
Packit 0848f5
    int i, p;
Packit 0848f5
    if (!mynod) {
Packit 0848f5
        ptr = dest;
Packit 0848f5
        for (i = 0; i < array->namect; i++) {
Packit 0848f5
            p = snprintf(ptr, len, "%s,", array->names[i]);
Packit 0848f5
            ptr += p;
Packit 0848f5
        }
Packit 0848f5
        /* chop off that last comma */
Packit 0848f5
        dest[strlen(dest) - 1] = '\0';
Packit 0848f5
    }
Packit 0848f5
    MPI_Bcast(dest, len, MPI_CHAR, 0, MPI_COMM_WORLD);
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
void reverse_str(int mynod, int len, ADIO_cb_name_array array, char *dest)
Packit 0848f5
{
Packit 0848f5
    char *ptr;
Packit 0848f5
    int i, p;
Packit 0848f5
    if (!mynod) {
Packit 0848f5
        ptr = dest;
Packit 0848f5
        for (i = (array->namect - 1); i >= 0; i--) {
Packit 0848f5
            p = snprintf(ptr, len, "%s,", array->names[i]);
Packit 0848f5
            ptr += p;
Packit 0848f5
        }
Packit 0848f5
        dest[strlen(dest) - 1] = '\0';
Packit 0848f5
    }
Packit 0848f5
    MPI_Bcast(dest, len, MPI_CHAR, 0, MPI_COMM_WORLD);
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
void reverse_alternating_str(int mynod, int len, ADIO_cb_name_array array, char *dest)
Packit 0848f5
{
Packit 0848f5
    char *ptr;
Packit 0848f5
    int i, p;
Packit 0848f5
    if (!mynod) {
Packit 0848f5
        ptr = dest;
Packit 0848f5
        /* evens */
Packit 0848f5
        for (i = (array->namect - 1); i >= 0; i -= 2) {
Packit 0848f5
            p = snprintf(ptr, len, "%s,", array->names[i]);
Packit 0848f5
            ptr += p;
Packit 0848f5
        }
Packit 0848f5
        /* odds */
Packit 0848f5
        for (i = (array->namect - 2); i > 0; i -= 2) {
Packit 0848f5
            p = snprintf(ptr, len, "%s,", array->names[i]);
Packit 0848f5
            ptr += p;
Packit 0848f5
        }
Packit 0848f5
        dest[strlen(dest) - 1] = '\0';
Packit 0848f5
    }
Packit 0848f5
    MPI_Bcast(dest, len, MPI_CHAR, 0, MPI_COMM_WORLD);
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
void simple_shuffle_str(int mynod, int len, ADIO_cb_name_array array, char *dest)
Packit 0848f5
{
Packit 0848f5
    char *ptr;
Packit 0848f5
    int i, p;
Packit 0848f5
    if (!mynod) {
Packit 0848f5
        ptr = dest;
Packit 0848f5
        for (i = (array->namect / 2); i < array->namect; i++) {
Packit 0848f5
            p = snprintf(ptr, len, "%s,", array->names[i]);
Packit 0848f5
            ptr += p;
Packit 0848f5
        }
Packit 0848f5
        for (i = 0; i < (array->namect / 2); i++) {
Packit 0848f5
            p = snprintf(ptr, len, "%s,", array->names[i]);
Packit 0848f5
            ptr += p;
Packit 0848f5
        }
Packit 0848f5
        dest[strlen(dest) - 1] = '\0';
Packit 0848f5
    }
Packit 0848f5
    MPI_Bcast(dest, len, MPI_CHAR, 0, MPI_COMM_WORLD);
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
int main(int argc, char **argv)
Packit 0848f5
{
Packit 0848f5
    int i, mynod, nprocs, len, errs = 0, sum_errs = 0, verbose = 0;
Packit 0848f5
    char *filename;
Packit 0848f5
    char *cb_config_string;
Packit 0848f5
    int cb_config_len;
Packit 0848f5
    ADIO_cb_name_array array;
Packit 0848f5
Packit 0848f5
Packit 0848f5
    MPI_Init(&argc, &argv);
Packit 0848f5
    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
Packit 0848f5
    MPI_Comm_rank(MPI_COMM_WORLD, &mynod);
Packit 0848f5
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 (!mynod) {
Packit 0848f5
        filename = "testfile";
Packit 0848f5
        len = strlen(filename);
Packit 0848f5
        MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
Packit 0848f5
        MPI_Bcast(filename, len + 1, MPI_CHAR, 0, MPI_COMM_WORLD);
Packit 0848f5
    }
Packit 0848f5
    else {
Packit 0848f5
        MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
Packit 0848f5
        filename = (char *) malloc(len + 1);
Packit 0848f5
        MPI_Bcast(filename, len + 1, MPI_CHAR, 0, MPI_COMM_WORLD);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    /* want to hint the cb_config_list, but do so in a non-sequential way */
Packit 0848f5
    cb_gather_name_array(MPI_COMM_WORLD, &array);
Packit 0848f5
Packit 0848f5
    /* sanity check */
Packit 0848f5
    if (!mynod) {
Packit 0848f5
        if (array->namect < 2) {
Packit 0848f5
            fprintf(stderr, "Run this test on two or more hosts\n");
Packit 0848f5
            MPI_Abort(MPI_COMM_WORLD, 1);
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
    /* get space for the permuted cb_config_string */
Packit 0848f5
    if (!mynod) {
Packit 0848f5
        cb_config_len = 0;
Packit 0848f5
        for (i = 0; i < array->namect; i++) {
Packit 0848f5
            /* +1: space for either a , or \0 if last */
Packit 0848f5
            cb_config_len += strlen(array->names[i]) + 1;
Packit 0848f5
        }
Packit 0848f5
        ++cb_config_len;
Packit 0848f5
    }
Packit 0848f5
    MPI_Bcast(&cb_config_len, 1, MPI_INT, 0, MPI_COMM_WORLD);
Packit 0848f5
    if ((cb_config_string = malloc(cb_config_len)) == NULL) {
Packit 0848f5
        perror("malloc");
Packit 0848f5
        MPI_Abort(MPI_COMM_WORLD, 1);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    /* first, no hinting */
Packit 0848f5
    errs += test_file(filename, mynod, nprocs, NULL, "collective w/o hinting", verbose);
Packit 0848f5
Packit 0848f5
    /* hint, but no change in order */
Packit 0848f5
    default_str(mynod, cb_config_len, array, cb_config_string);
Packit 0848f5
    errs += test_file(filename, mynod, nprocs, cb_config_string,
Packit 0848f5
                      "collective w/ hinting: default order", verbose);
Packit 0848f5
Packit 0848f5
    /*  reverse order */
Packit 0848f5
    reverse_str(mynod, cb_config_len, array, cb_config_string);
Packit 0848f5
    errs += test_file(filename, mynod, nprocs, cb_config_string,
Packit 0848f5
                      "collective w/ hinting: reverse order", verbose);
Packit 0848f5
Packit 0848f5
    /* reverse, every other */
Packit 0848f5
    reverse_alternating_str(mynod, cb_config_len, array, cb_config_string);
Packit 0848f5
    errs += test_file(filename, mynod, nprocs, cb_config_string,
Packit 0848f5
                      "collective w/ hinting: permutation1", verbose);
Packit 0848f5
Packit 0848f5
    /* second half, first half */
Packit 0848f5
    simple_shuffle_str(mynod, cb_config_len, array, cb_config_string);
Packit 0848f5
    errs += test_file(filename, mynod, nprocs, cb_config_string,
Packit 0848f5
                      "collective w/ hinting: permutation2", verbose);
Packit 0848f5
Packit 0848f5
    MPI_Allreduce(&errs, &sum_errs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
Packit 0848f5
Packit 0848f5
    if (!mynod) {
Packit 0848f5
        if (sum_errs)
Packit 0848f5
            fprintf(stderr, "Found %d error cases\n", sum_errs);
Packit 0848f5
        else
Packit 0848f5
            printf(" No Errors\n");
Packit 0848f5
    }
Packit 0848f5
    if (mynod)
Packit 0848f5
        free(filename);
Packit 0848f5
    free(cb_config_string);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
#define SEEDER(x,y,z) ((x)*1000000 + (y) + (x)*(z))
Packit 0848f5
Packit 0848f5
int test_file(char *filename, int mynod, int nprocs, char *cb_hosts, const char *msg, int verbose)
Packit 0848f5
{
Packit 0848f5
    MPI_Datatype typevec, newtype, t[3];
Packit 0848f5
    int *buf, i, b[3], errcode, errors = 0;
Packit 0848f5
    MPI_File fh;
Packit 0848f5
    MPI_Aint d[3];
Packit 0848f5
    MPI_Request request;
Packit 0848f5
    MPI_Status status;
Packit 0848f5
    int SIZE = (STARTING_SIZE / nprocs) * nprocs;
Packit 0848f5
    MPI_Info info;
Packit 0848f5
Packit 0848f5
    if (mynod == 0 && verbose)
Packit 0848f5
        fprintf(stderr, "%s\n", msg);
Packit 0848f5
Packit 0848f5
    buf = (int *) malloc(SIZE * sizeof(int));
Packit 0848f5
    if (buf == NULL) {
Packit 0848f5
        perror("test_file");
Packit 0848f5
        MPI_Abort(MPI_COMM_WORLD, -1);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
Packit 0848f5
    if (cb_hosts != NULL) {
Packit 0848f5
        MPI_Info_create(&info;;
Packit 0848f5
        MPI_Info_set(info, "cb_config_list", cb_hosts);
Packit 0848f5
    }
Packit 0848f5
    else {
Packit 0848f5
        info = MPI_INFO_NULL;
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_Type_vector(SIZE / nprocs, 1, nprocs, MPI_INT, &typevec);
Packit 0848f5
Packit 0848f5
    b[0] = b[1] = b[2] = 1;
Packit 0848f5
    d[0] = 0;
Packit 0848f5
    d[1] = mynod * sizeof(int);
Packit 0848f5
    d[2] = SIZE * sizeof(int);
Packit 0848f5
    t[0] = MPI_LB;
Packit 0848f5
    t[1] = typevec;
Packit 0848f5
    t[2] = MPI_UB;
Packit 0848f5
Packit 0848f5
    MPI_Type_struct(3, b, d, t, &newtype);
Packit 0848f5
    MPI_Type_commit(&newtype);
Packit 0848f5
    MPI_Type_free(&typevec);
Packit 0848f5
Packit 0848f5
    if (!mynod) {
Packit 0848f5
        if (verbose)
Packit 0848f5
            fprintf(stderr, "\ntesting noncontiguous in memory, noncontiguous "
Packit 0848f5
                    "in file using collective I/O\n");
Packit 0848f5
        MPI_File_delete(filename, info);
Packit 0848f5
    }
Packit 0848f5
    MPI_Barrier(MPI_COMM_WORLD);
Packit 0848f5
Packit 0848f5
    errcode = MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, info, &fh;;
Packit 0848f5
    if (errcode != MPI_SUCCESS) {
Packit 0848f5
        handle_error(errcode, "MPI_File_open");
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", info);
Packit 0848f5
Packit 0848f5
    for (i = 0; i < SIZE; i++)
Packit 0848f5
        buf[i] = SEEDER(mynod, i, SIZE);
Packit 0848f5
    errcode = MPI_File_iwrite_all(fh, buf, 1, newtype, &request);
Packit 0848f5
    if (errcode != MPI_SUCCESS) {
Packit 0848f5
        handle_error(errcode, "nc mem - nc file: MPI_File_iwrite_all");
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_Barrier(MPI_COMM_WORLD);
Packit 0848f5
    MPI_Wait(&request, &status);
Packit 0848f5
Packit 0848f5
    for (i = 0; i < SIZE; i++)
Packit 0848f5
        buf[i] = -1;
Packit 0848f5
Packit 0848f5
    errcode = MPI_File_iread_at_all(fh, 0, buf, 1, newtype, &request);
Packit 0848f5
    if (errcode != MPI_SUCCESS) {
Packit 0848f5
        handle_error(errcode, "nc mem - nc file: MPI_File_iread_at_all");
Packit 0848f5
    }
Packit 0848f5
    MPI_Wait(&request, &status);
Packit 0848f5
Packit 0848f5
    /* the verification for N compute nodes is tricky. Say we have 3
Packit 0848f5
     * processors.
Packit 0848f5
     * process 0 sees: 0 -1 -1 3 -1 -1 ...
Packit 0848f5
     * process 1 sees: -1 34 -1 -1 37 -1 ...
Packit 0848f5
     * process 2 sees: -1 -1 68 -1 -1 71 ... */
Packit 0848f5
Packit 0848f5
    /* verify those leading -1s exist if they should */
Packit 0848f5
    for (i = 0; i < mynod; i++) {
Packit 0848f5
        if (buf[i] != -1) {
Packit 0848f5
            if (verbose)
Packit 0848f5
                fprintf(stderr, "Process %d: buf is %d, should be -1\n", mynod, buf[i]);
Packit 0848f5
            errors++;
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
    /* now the modulo games are hairy.  processor 0 sees real data in the 0th,
Packit 0848f5
     * 3rd, 6th... elements of the buffer (assuming nprocs==3).  proc 1 sees
Packit 0848f5
     * the data in 1st, 4th, 7th..., and proc 2 sees it in 2nd, 5th, 8th */
Packit 0848f5
Packit 0848f5
    for (/* 'i' set in above loop */ ; i < SIZE; i++) {
Packit 0848f5
        if (((i - mynod) % nprocs) && buf[i] != -1) {
Packit 0848f5
            if (verbose)
Packit 0848f5
                fprintf(stderr, "Process %d: buf %d is %d, should be -1\n", mynod, i, buf[i]);
Packit 0848f5
            errors++;
Packit 0848f5
        }
Packit 0848f5
        if (!((i - mynod) % nprocs) && buf[i] != SEEDER(mynod, i, SIZE)) {
Packit 0848f5
            if (verbose)
Packit 0848f5
                fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
Packit 0848f5
                        mynod, i, buf[i], SEEDER(mynod, i, SIZE));
Packit 0848f5
            errors++;
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
    MPI_File_close(&fh;;
Packit 0848f5
Packit 0848f5
    MPI_Barrier(MPI_COMM_WORLD);
Packit 0848f5
Packit 0848f5
    if (!mynod) {
Packit 0848f5
        if (verbose)
Packit 0848f5
            fprintf(stderr, "\ntesting noncontiguous in memory, contiguous in "
Packit 0848f5
                    "file using collective I/O\n");
Packit 0848f5
        MPI_File_delete(filename, info);
Packit 0848f5
    }
Packit 0848f5
    MPI_Barrier(MPI_COMM_WORLD);
Packit 0848f5
Packit 0848f5
    MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, info, &fh;;
Packit 0848f5
Packit 0848f5
    for (i = 0; i < SIZE; i++)
Packit 0848f5
        buf[i] = SEEDER(mynod, i, SIZE);
Packit 0848f5
    errcode = MPI_File_iwrite_at_all(fh, mynod * (SIZE / nprocs) * sizeof(int),
Packit 0848f5
                                     buf, 1, newtype, &request);
Packit 0848f5
    if (errcode != MPI_SUCCESS)
Packit 0848f5
        handle_error(errcode, "nc mem - c file: MPI_File_iwrite_at_all");
Packit 0848f5
Packit 0848f5
    MPI_Barrier(MPI_COMM_WORLD);
Packit 0848f5
    MPI_Wait(&request, &status);
Packit 0848f5
Packit 0848f5
    for (i = 0; i < SIZE; i++)
Packit 0848f5
        buf[i] = -1;
Packit 0848f5
Packit 0848f5
    errcode = MPI_File_iread_at_all(fh, mynod * (SIZE / nprocs) * sizeof(int),
Packit 0848f5
                                    buf, 1, newtype, &request);
Packit 0848f5
    if (errcode != MPI_SUCCESS)
Packit 0848f5
        handle_error(errcode, "nc mem - c file: MPI_File_iread_at_all");
Packit 0848f5
    MPI_Wait(&request, &status);
Packit 0848f5
Packit 0848f5
    /* just like as above */
Packit 0848f5
    for (i = 0; i < mynod; i++) {
Packit 0848f5
        if (buf[i] != -1) {
Packit 0848f5
            if (verbose)
Packit 0848f5
                fprintf(stderr, "Process %d: buf is %d, should be -1\n", mynod, buf[i]);
Packit 0848f5
            errors++;
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
    for (/* i set in above loop */ ; i < SIZE; i++) {
Packit 0848f5
        if (((i - mynod) % nprocs) && buf[i] != -1) {
Packit 0848f5
            if (verbose)
Packit 0848f5
                fprintf(stderr, "Process %d: buf %d is %d, should be -1\n", mynod, i, buf[i]);
Packit 0848f5
            errors++;
Packit 0848f5
        }
Packit 0848f5
        if (!((i - mynod) % nprocs) && buf[i] != SEEDER(mynod, i, SIZE)) {
Packit 0848f5
            if (verbose)
Packit 0848f5
                fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
Packit 0848f5
                        mynod, i, buf[i], SEEDER(mynod, i, SIZE));
Packit 0848f5
            errors++;
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_File_close(&fh;;
Packit 0848f5
Packit 0848f5
    MPI_Barrier(MPI_COMM_WORLD);
Packit 0848f5
Packit 0848f5
    if (!mynod) {
Packit 0848f5
        if (verbose)
Packit 0848f5
            fprintf(stderr, "\ntesting contiguous in memory, noncontiguous in "
Packit 0848f5
                    "file using collective I/O\n");
Packit 0848f5
        MPI_File_delete(filename, info);
Packit 0848f5
    }
Packit 0848f5
    MPI_Barrier(MPI_COMM_WORLD);
Packit 0848f5
Packit 0848f5
    MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, info, &fh;;
Packit 0848f5
Packit 0848f5
    MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", info);
Packit 0848f5
Packit 0848f5
    for (i = 0; i < SIZE; i++)
Packit 0848f5
        buf[i] = SEEDER(mynod, i, SIZE);
Packit 0848f5
    errcode = MPI_File_iwrite_all(fh, buf, SIZE, MPI_INT, &request);
Packit 0848f5
    if (errcode != MPI_SUCCESS)
Packit 0848f5
        handle_error(errcode, "c mem - nc file: MPI_File_iwrite_all");
Packit 0848f5
Packit 0848f5
    MPI_Barrier(MPI_COMM_WORLD);
Packit 0848f5
    MPI_Wait(&request, &status);
Packit 0848f5
Packit 0848f5
    for (i = 0; i < SIZE; i++)
Packit 0848f5
        buf[i] = -1;
Packit 0848f5
Packit 0848f5
    errcode = MPI_File_iread_at_all(fh, 0, buf, SIZE, MPI_INT, &request);
Packit 0848f5
    if (errcode != MPI_SUCCESS)
Packit 0848f5
        handle_error(errcode, "c mem - nc file: MPI_File_iread_at_all");
Packit 0848f5
    MPI_Wait(&request, &status);
Packit 0848f5
Packit 0848f5
    /* same crazy checking */
Packit 0848f5
    for (i = 0; i < SIZE; i++) {
Packit 0848f5
        if (buf[i] != SEEDER(mynod, i, SIZE)) {
Packit 0848f5
            if (verbose)
Packit 0848f5
                fprintf(stderr, "Process %d: buf %d is %d, should be %d\n",
Packit 0848f5
                        mynod, i, buf[i], SEEDER(mynod, i, SIZE));
Packit 0848f5
            errors++;
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_File_close(&fh;;
Packit 0848f5
Packit 0848f5
    MPI_Type_free(&newtype);
Packit 0848f5
    free(buf);
Packit 0848f5
    if (info != MPI_INFO_NULL)
Packit 0848f5
        MPI_Info_free(&info;;
Packit 0848f5
    return errors;
Packit 0848f5
}