|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* (C) 2001 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 <stdlib.h>
|
|
Packit |
0848f5 |
#include "mpitestconf.h"
|
|
Packit |
0848f5 |
#include "mpitest.h"
|
|
Packit |
0848f5 |
#ifdef HAVE_STRING_H
|
|
Packit |
0848f5 |
#include <string.h>
|
|
Packit |
0848f5 |
#endif
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
static char MTestDescrip[] = "Test freeing keyvals while still attached to \
|
|
Packit |
0848f5 |
a win, then make sure that the keyval delete code are still \
|
|
Packit |
0848f5 |
executed";
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Copy increments the attribute value */
|
|
Packit |
0848f5 |
/* Note that we can really ignore this because there is no win dup */
|
|
Packit |
0848f5 |
int copy_fn(MPI_Win oldwin, int keyval, void *extra_state,
|
|
Packit |
0848f5 |
void *attribute_val_in, void *attribute_val_out, int *flag);
|
|
Packit |
0848f5 |
int copy_fn(MPI_Win oldwin, int keyval, void *extra_state,
|
|
Packit |
0848f5 |
void *attribute_val_in, void *attribute_val_out, int *flag)
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
/* Copy the address of the attribute */
|
|
Packit |
0848f5 |
*(void **) attribute_val_out = attribute_val_in;
|
|
Packit |
0848f5 |
/* Change the value */
|
|
Packit |
0848f5 |
*(int *) attribute_val_in = *(int *) attribute_val_in + 1;
|
|
Packit |
0848f5 |
*flag = 1;
|
|
Packit |
0848f5 |
return MPI_SUCCESS;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Delete decrements the attribute value */
|
|
Packit |
0848f5 |
int delete_fn(MPI_Win win, int keyval, void *attribute_val, void *extra_state);
|
|
Packit |
0848f5 |
int delete_fn(MPI_Win win, int keyval, void *attribute_val, void *extra_state)
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
*(int *) attribute_val = *(int *) attribute_val - 1;
|
|
Packit |
0848f5 |
return MPI_SUCCESS;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int errs = 0;
|
|
Packit |
0848f5 |
int attrval;
|
|
Packit |
0848f5 |
int i, key[32], keyval;
|
|
Packit |
0848f5 |
MPI_Win win;
|
|
Packit |
0848f5 |
MTest_Init(&argc, &argv);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
while (MTestGetWin(&win, 0)) {
|
|
Packit |
0848f5 |
if (win == MPI_WIN_NULL)
|
|
Packit |
0848f5 |
continue;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Win_create_keyval(copy_fn, delete_fn, &keyval, (void *) 0);
|
|
Packit |
0848f5 |
attrval = 1;
|
|
Packit |
0848f5 |
MPI_Win_set_attr(win, keyval, (void *) &attrval);
|
|
Packit |
0848f5 |
/* See MPI-1, 5.7.1. Freeing the keyval does not remove it if it
|
|
Packit |
0848f5 |
* is in use in an attribute */
|
|
Packit |
0848f5 |
MPI_Win_free_keyval(&keyval);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* We create some dummy keyvals here in case the same keyval
|
|
Packit |
0848f5 |
* is reused */
|
|
Packit |
0848f5 |
for (i = 0; i < 32; i++) {
|
|
Packit |
0848f5 |
MPI_Win_create_keyval(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, &key[i], (void *) 0);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTestFreeWin(&win);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Check that the original attribute was freed */
|
|
Packit |
0848f5 |
if (attrval != 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("Attribute not decremented when win %s freed\n", MTestGetWinName());
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
/* Free those other keyvals */
|
|
Packit |
0848f5 |
for (i = 0; i < 32; i++) {
|
|
Packit |
0848f5 |
MPI_Win_free_keyval(&key[i]);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
MTest_Finalize(errs);
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|