Blame test/mpi/manual/mpi_t/mpit_test.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2011 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
/* A simple test of the proposed MPI_T_ interface that queries all of
Packit 0848f5
 * the control variables exposed by the MPI implememtation and prints
Packit 0848f5
 * them to stdout.
Packit 0848f5
 *
Packit 0848f5
 * Author: Dave Goodell 
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#include <stdlib.h>
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include <assert.h>
Packit 0848f5
#include <math.h>
Packit 0848f5
#include "mpitestconf.h"
Packit 0848f5
Packit 0848f5
#if !defined(USE_STRICT_MPI) && defined(MPICH)
Packit 0848f5
int main(int argc, char **argv)
Packit 0848f5
{
Packit 0848f5
    int i;
Packit 0848f5
    int num;
Packit 0848f5
    int rank, size;
Packit 0848f5
/*#define STR_SZ (15)*/
Packit 0848f5
#define STR_SZ (50)
Packit 0848f5
    int name_len = STR_SZ;
Packit 0848f5
    char name[STR_SZ] = "";
Packit 0848f5
    int desc_len = STR_SZ;
Packit 0848f5
    char desc[STR_SZ] = "";
Packit 0848f5
    int verb;
Packit 0848f5
    MPI_Datatype dtype;
Packit 0848f5
    int count;
Packit 0848f5
    int bind;
Packit 0848f5
    int scope;
Packit 0848f5
    int provided;
Packit 0848f5
    int initialize_mpi = 0;
Packit 0848f5
    MPI_T_cvar_handle handle;
Packit 0848f5
    MPI_T_enum enumtype;
Packit 0848f5
Packit 0848f5
    provided = 0xdeadbeef;
Packit 0848f5
    MPI_T_init_thread(MPI_THREAD_SINGLE, &provided);
Packit 0848f5
    assert(provided != 0xdeadbeef);
Packit 0848f5
Packit 0848f5
    if (initialize_mpi) {
Packit 0848f5
        MPI_Init(&argc, &argv);
Packit 0848f5
        MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit 0848f5
        MPI_Comm_size(MPI_COMM_WORLD, &size);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    num = 0xdeadbeef;
Packit 0848f5
    MPI_T_cvar_get_num(&num);
Packit 0848f5
    printf("get_num=%d\n", num);
Packit 0848f5
    assert(num != 0xdeadbeef);
Packit 0848f5
    for (i = 0; i < num; ++i) {
Packit 0848f5
        name_len = desc_len = STR_SZ;
Packit 0848f5
        MPI_T_cvar_get_info(i, name, &name_len, &verb, &dtype, &enumtype, desc, &desc_len, &bind,
Packit 0848f5
                            &scope);
Packit 0848f5
        printf("index=%d\n", i);
Packit 0848f5
        printf("--> name='%s' name_len=%d desc='%s' desc_len=%d\n", name, name_len, desc, desc_len);
Packit 0848f5
        printf("--> verb=%d dtype=%#x bind=%d scope=%d\n", verb, dtype, bind, scope);
Packit 0848f5
Packit 0848f5
        MPI_T_cvar_handle_alloc(i, NULL, &handle, &count);
Packit 0848f5
        printf("--> handle allocated: handle=%p count=%d\n", handle, count);
Packit 0848f5
        if (dtype == MPI_INT) {
Packit 0848f5
            int val = 0xdeadbeef;
Packit 0848f5
            MPI_T_cvar_read(handle, &val;;
Packit 0848f5
            printf("--> val=%d\n", val);
Packit 0848f5
            ++val;
Packit 0848f5
            MPI_T_cvar_write(handle, &val;;
Packit 0848f5
            val = 0xdeadbeef;
Packit 0848f5
            MPI_T_cvar_read(handle, &val;;
Packit 0848f5
            printf("--> incremented val=%d\n", val);
Packit 0848f5
        }
Packit 0848f5
        else if (dtype == MPI_DOUBLE) {
Packit 0848f5
            double val = NAN;
Packit 0848f5
            MPI_T_cvar_read(handle, &val;;
Packit 0848f5
            printf("--> val=%f\n", val);
Packit 0848f5
            val *= 2.0;
Packit 0848f5
            MPI_T_cvar_write(handle, &val;;
Packit 0848f5
            val = NAN;
Packit 0848f5
            MPI_T_cvar_read(handle, &val;;
Packit 0848f5
            printf("--> doubled val=%f\n", val);
Packit 0848f5
        }
Packit 0848f5
        else if (dtype == MPI_CHAR) {
Packit 0848f5
            char *str = malloc(count + 1);
Packit 0848f5
            MPI_T_cvar_read(handle, str);
Packit 0848f5
            printf("--> str='%s'\n", str);
Packit 0848f5
            /* just write the string back unmodified for now */
Packit 0848f5
            MPI_T_cvar_write(handle, str);
Packit 0848f5
            MPI_T_cvar_read(handle, str);
Packit 0848f5
            printf("--> written-then-read str='%s'\n", str);
Packit 0848f5
        }
Packit 0848f5
        MPI_T_cvar_handle_free(&handle);
Packit 0848f5
        printf("\n");
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    if (initialize_mpi) {
Packit 0848f5
        MPI_Finalize();
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_T_finalize();
Packit 0848f5
Packit 0848f5
    return 0;
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
#else
Packit 0848f5
/* Simple null program to allow building this file with non-MPICH
Packit 0848f5
   implementations */
Packit 0848f5
int main(int argc, char **argv)
Packit 0848f5
{
Packit 0848f5
    MPI_Init(&argc, &argv);
Packit 0848f5
    printf(" No Errors\n");
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}
Packit 0848f5
#endif