Blame test/mpi/rma/allocmem.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2003 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 "mpitest.h"
Packit 0848f5
Packit 0848f5
/*
Packit 0848f5
static char MTEST_Descrip[] = "Simple test that alloc_mem and free_mem work together";
Packit 0848f5
*/
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
    int errs = 0, err;
Packit 0848f5
    int j, count;
Packit 0848f5
    char *ap;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
Packit 0848f5
    for (count = 1; count < 128000; count *= 2) {
Packit 0848f5
Packit 0848f5
        err = MPI_Alloc_mem(count, MPI_INFO_NULL, &ap);
Packit 0848f5
        if (err) {
Packit 0848f5
            int errclass;
Packit 0848f5
            /* An error of  MPI_ERR_NO_MEM is allowed */
Packit 0848f5
            MPI_Error_class(err, &errclass);
Packit 0848f5
            if (errclass != MPI_ERR_NO_MEM) {
Packit 0848f5
                errs++;
Packit 0848f5
                MTestPrintError(err);
Packit 0848f5
            }
Packit 0848f5
Packit 0848f5
        }
Packit 0848f5
        else {
Packit 0848f5
            /* Access all of this memory */
Packit 0848f5
            for (j = 0; j < count; j++) {
Packit 0848f5
                ap[j] = (char) (j & 0x7f);
Packit 0848f5
            }
Packit 0848f5
            MPI_Free_mem(ap);
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}