1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
/*
* Copyright (C) by Argonne National Laboratory
* See COPYRIGHT in top-level directory
*/
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include "mpitestconf.h"
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "mpitest.h"
#define NUM_INFOS 128
int modify_info(MPI_Info * infos, const char *get_key, const char *get_value,
const char *set_key, const char *set_value);
int main(int argc, char *argv[])
{
MPI_Info infos[NUM_INFOS];
int i, nerrs = 0;
/* MPI_Info functions can be called before MPI_Init(). */
for (i = 0; i < NUM_INFOS; i++)
MPI_Info_create(&infos[i]);
/* Modify some. */
nerrs += modify_info(infos, NULL, NULL, "key1", "value1");
nerrs += modify_info(infos, "key1", "value1", "key2", "value2");
MPI_Init(&argc, &argv);
/* Modify some. */
nerrs += modify_info(infos, "key2", "value2", "key3", "value3");
MPI_Finalize();
/* MPI_Info functions can be called after MPI_Finalize(). */
/* Modify some. */
nerrs += modify_info(infos, "key3", "value3", "key4", "value4");
nerrs += modify_info(infos, "key4", "value4", NULL, NULL);
for (i = 0; i < NUM_INFOS; i++)
MPI_Info_free(&infos[i]);
/* Let's check if we can create all info objects now. This checks if the
* MPICH implementation internally cleans up the MPI_Info handle pool
* properly when all handles are freed and that pool is still
* reinitialized. */
for (i = 0; i < NUM_INFOS; i++)
MPI_Info_create(&infos[i]);
for (i = 0; i < NUM_INFOS; i++)
MPI_Info_free(&infos[i]);
if (nerrs) {
printf(" Found %d errors\n", nerrs);
} else {
printf(" No Errors\n");
}
fflush(stdout);
return nerrs ? 1 : 0;;
}
int modify_info(MPI_Info * infos, const char *get_key, const char *get_value,
const char *set_key, const char *set_value)
{
int i, nerrs = 0;
static int num_modified = 0;
/* Duplicate some info objects to check if MPI_Info_dup() works. Always
* 50% will be duplicated and replaced. */
for (i = 0; i < NUM_INFOS; i += (1 << (num_modified + 1))) {
int j;
for (j = i; j < i + (1 << num_modified); j++) {
if (j >= NUM_INFOS)
continue;
MPI_Info newinfo;
MPI_Info_dup(infos[i], &newinfo);
/* infos[i] is not needed. */
MPI_Info_free(&infos[i]);
/* newinfo becomes a new infos[i]. */
infos[i] = newinfo;
}
}
num_modified += 1;
if ((1 << num_modified) >= NUM_INFOS) {
num_modified = 0;
}
/* Get values. */
if (get_key && get_value) {
for (i = 0; i < NUM_INFOS; i++) {
int valuelen = MPI_MAX_INFO_VAL, flag;
char value[MPI_MAX_INFO_VAL];
MPI_Info_get_string(infos[i], get_key, &valuelen, value, &flag);
if (!flag) {
/* infos[i] should have get_key:get_value pair */
nerrs++;
} else if (strcmp(value, get_value) != 0) {
/* infos[i] should have get_key:get_value pair */
nerrs++;
}
}
}
/* Create new info objects to check if MPI_Info_create() works. Always 50%
* will be newly created and replaced. */
for (i = 0; i < NUM_INFOS; i += (1 << (num_modified + 1))) {
int j;
for (j = i; j < i + (1 << num_modified); j++) {
if (j >= NUM_INFOS)
continue;
MPI_Info_free(&infos[i]);
MPI_Info_create(&infos[i]);
}
}
num_modified += 1;
if ((1 << num_modified) >= NUM_INFOS) {
num_modified = 0;
}
/* Set values. */
if (set_key && set_value) {
for (i = 0; i < NUM_INFOS; i++) {
MPI_Info_set(infos[i], set_key, set_value);
}
}
return nerrs;
}
|