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
|
/*
* Copyright (C) by Argonne National Laboratory
* See COPYRIGHT in top-level directory
*/
/* Test of info that makes use of the extended handles, including
inserts and deletes */
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include "mpitest.h"
#include "mpitestconf.h"
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifndef MAX_INFOS
#define MAX_INFOS 4000
#endif
#define MAX_ERRORS 10
#define info_list 16
/* #define DBG */
#ifdef DEBUG
#define DBGPRINTF(a) printf a; fflush(stdout)
#else
#define DBGPRINTF(a)
#endif
int main(int argc, char *argv[])
{
MPI_Info infos[MAX_INFOS];
char key[64], value[64];
int errs = 0;
int i, j;
MTest_Init(&argc, &argv);
/* We create max_info items, then delete the middle third of them,
* then recreate them, then check them, then
* delete them all. This checks that the MPICH algorithm for
* handling large numbers of items works correctly; other MPI
* implementations should also be able to handle this */
/* Create them all */
for (i = 0; i < MAX_INFOS; i++) {
MPI_Info_create(&infos[i]);
DBGPRINTF(("Info handle is %x\n", infos[i]));
for (j = 0; j < info_list; j++) {
sprintf(key, "key%d-%d", i, j);
sprintf(value, "value%d-%d", i, j);
DBGPRINTF(("Creating key/value %s=%s\n", key, value));
MPI_Info_set(infos[i], key, value);
}
#ifdef DBG
{
int nkeys;
MPI_Info_get_nkeys(infos[0], &nkeys);
if (nkeys != info_list) {
printf("infos[0] changed at %d info\n", i);
}
}
#endif
}
/* Delete the middle set */
for (i = MAX_INFOS / 3; i < (2 * MAX_INFOS / 3); i++) {
MPI_Info_free(&infos[i]);
}
/* Recreate the middle set */
for (i = MAX_INFOS / 3; i < (2 * MAX_INFOS / 3); i++) {
MPI_Info_create(&infos[i]);
DBGPRINTF(("Info handle is %x\n", infos[i]));
for (j = 0; j < info_list; j++) {
sprintf(key, "key%d-%d", i, j);
sprintf(value, "value%d-%d", i, j);
DBGPRINTF(("Creating key/value %s=%s\n", key, value));
MPI_Info_set(infos[i], key, value);
}
}
/* Now, check that they are still valid */
for (i = 0; i < MAX_INFOS; i++) {
int nkeys;
/*printf("info = %x\n", infos[i]);
* print_handle(infos[i]); printf("\n"); */
MPI_Info_get_nkeys(infos[i], &nkeys);
if (nkeys != info_list) {
errs++;
if (errs < MAX_ERRORS) {
printf("Wrong number of keys for info %d; got %d, should be %d\n",
i, nkeys, info_list);
}
}
for (j = 0; j < nkeys; j++) {
char keystr[64];
char valstr[64];
int flag;
MPI_Info_get_nthkey(infos[i], j, key);
sprintf(keystr, "key%d-%d", i, j);
if (strcmp(keystr, key) != 0) {
errs++;
if (errs < MAX_ERRORS) {
printf("Wrong key for info %d; got %s expected %s\n", i, key, keystr);
}
continue;
}
MPI_Info_get(infos[i], key, 64, value, &flag);
if (!flag) {
errs++;
if (errs < MAX_ERRORS) {
printf("Get failed to return value for info %d\n", i);
}
continue;
}
sprintf(valstr, "value%d-%d", i, j);
if (strcmp(valstr, value) != 0) {
errs++;
if (errs < MAX_ERRORS) {
printf("Wrong value for info %d; got %s expected %s\n", i, value, valstr);
}
}
}
}
for (i = 0; i < MAX_INFOS; i++) {
MPI_Info_free(&infos[i]);
}
MTest_Finalize(errs);
return MTestReturnValue(errs);
}
|