|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* (C) 2009 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include "mpitest.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
static char MTestDescrip[] = "Test creating and inserting attributes in \
|
|
Packit Service |
c5cf8c |
different orders to ensure that the list management code handles all cases.";
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int checkAttrs(MPI_Comm, int, int[], int[]);
|
|
Packit Service |
c5cf8c |
int delete_fn(MPI_Comm, int, void *, void *);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define NKEYS 5
|
|
Packit Service |
c5cf8c |
static int key[NKEYS]; /* Keys in creation order */
|
|
Packit Service |
c5cf8c |
static int keyorder[NKEYS]; /* Index (into key) of keys in order added to comm
|
|
Packit Service |
c5cf8c |
* (key[keyorder[0]] is first set) */
|
|
Packit Service |
c5cf8c |
static int nkeys = 0;
|
|
Packit Service |
c5cf8c |
static int ncall = 0;
|
|
Packit Service |
c5cf8c |
static int errs = 0;
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* Test that attributes on comm self are deleted in LIFO order
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char *argv[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int attrval[10];
|
|
Packit Service |
c5cf8c |
int wrank, i;
|
|
Packit Service |
c5cf8c |
MPI_Comm comm;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
comm = MPI_COMM_SELF;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Create key values */
|
|
Packit Service |
c5cf8c |
for (nkeys = 0; nkeys < NKEYS; nkeys++) {
|
|
Packit Service |
c5cf8c |
MPI_Comm_create_keyval(MPI_NULL_COPY_FN, delete_fn, &key[nkeys], (void *) 0);
|
|
Packit Service |
c5cf8c |
attrval[nkeys] = 1024 * nkeys;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Insert attribute in several orders. Test after put with get,
|
|
Packit Service |
c5cf8c |
* then delete, then confirm delete with get. */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_set_attr(comm, key[3], &attrval[3]);
|
|
Packit Service |
c5cf8c |
keyorder[0] = 3;
|
|
Packit Service |
c5cf8c |
MPI_Comm_set_attr(comm, key[2], &attrval[2]);
|
|
Packit Service |
c5cf8c |
keyorder[1] = 2;
|
|
Packit Service |
c5cf8c |
MPI_Comm_set_attr(comm, key[0], &attrval[0]);
|
|
Packit Service |
c5cf8c |
keyorder[2] = 0;
|
|
Packit Service |
c5cf8c |
MPI_Comm_set_attr(comm, key[1], &attrval[1]);
|
|
Packit Service |
c5cf8c |
keyorder[3] = 1;
|
|
Packit Service |
c5cf8c |
MPI_Comm_set_attr(comm, key[4], &attrval[4]);
|
|
Packit Service |
c5cf8c |
keyorder[4] = 4;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
errs += checkAttrs(comm, NKEYS, key, attrval);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < NKEYS; i++) {
|
|
Packit Service |
c5cf8c |
/* Save the key value so that we can compare it in the
|
|
Packit Service |
c5cf8c |
* delete function */
|
|
Packit Service |
c5cf8c |
int keyval = key[i];
|
|
Packit Service |
c5cf8c |
MPI_Comm_free_keyval(&keyval);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Finalize();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (wrank == 0) {
|
|
Packit Service |
c5cf8c |
if (ncall != nkeys) {
|
|
Packit Service |
c5cf8c |
printf("Deleted %d keys but should have deleted %d\n", ncall, nkeys);
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (errs == 0)
|
|
Packit Service |
c5cf8c |
printf(" No Errors\n");
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
printf(" Found %d errors\n", errs);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int checkAttrs(MPI_Comm comm, int n, int lkey[], int attrval[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int lerrs = 0;
|
|
Packit Service |
c5cf8c |
int i, flag, *val_p;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < n; i++) {
|
|
Packit Service |
c5cf8c |
MPI_Comm_get_attr(comm, lkey[i], &val_p, &flag;;
|
|
Packit Service |
c5cf8c |
if (!flag) {
|
|
Packit Service |
c5cf8c |
lerrs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Attribute for key %d not set\n", i);
|
|
Packit Service |
c5cf8c |
} else if (val_p != &attrval[i]) {
|
|
Packit Service |
c5cf8c |
lerrs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Atribute value for key %d not correct\n", i);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return lerrs;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* We *should* be deleting key[keyorder[nkeys-ncall]] */
|
|
Packit Service |
c5cf8c |
int delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
if (ncall >= nkeys) {
|
|
Packit Service |
c5cf8c |
printf("delete function called too many times!\n");
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* As of MPI 2.2, the order of deletion of attributes on
|
|
Packit Service |
c5cf8c |
* MPI_COMM_SELF is defined */
|
|
Packit Service |
c5cf8c |
if (MPI_VERSION > 2 || (MPI_VERSION == 2 && MPI_SUBVERSION >= 2)) {
|
|
Packit Service |
c5cf8c |
if (keyval != key[keyorder[nkeys - 1 - ncall]]) {
|
|
Packit Service |
c5cf8c |
printf("Expected key # %d but found key with value %d\n",
|
|
Packit Service |
c5cf8c |
keyorder[nkeys - 1 - ncall], keyval);
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
ncall++;
|
|
Packit Service |
c5cf8c |
return MPI_SUCCESS;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
int checkNoAttrs(MPI_Comm comm, int n, int lkey[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int lerrs = 0;
|
|
Packit Service |
c5cf8c |
int i, flag, *val_p;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i=0; i
|
|
Packit Service |
c5cf8c |
MPI_Comm_get_attr(comm, lkey[i], &val_p, &flag;;
|
|
Packit Service |
c5cf8c |
if (flag) {
|
|
Packit Service |
c5cf8c |
lerrs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Attribute for key %d set but should be deleted\n", i);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return lerrs;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
*/
|