|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* (C) 2003 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 "mpitest.h"
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
static char MTEST_Descrip[] = "Simple test of generalized requests";
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int query_fn(void *extra_state, MPI_Status * status);
|
|
Packit |
0848f5 |
int query_fn(void *extra_state, MPI_Status * status)
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
/* Set a default status */
|
|
Packit |
0848f5 |
status->MPI_SOURCE = MPI_UNDEFINED;
|
|
Packit |
0848f5 |
status->MPI_TAG = MPI_UNDEFINED;
|
|
Packit |
0848f5 |
MPI_Status_set_cancelled(status, 0);
|
|
Packit |
0848f5 |
MPI_Status_set_elements(status, MPI_BYTE, 0);
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int free_fn(void *extra_state);
|
|
Packit |
0848f5 |
int free_fn(void *extra_state)
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int *b = (int *) extra_state;
|
|
Packit |
0848f5 |
if (b)
|
|
Packit |
0848f5 |
*b = *b - 1;
|
|
Packit |
0848f5 |
/* The value returned by the free function is the error code
|
|
Packit |
0848f5 |
* returned by the wait/test function */
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int cancel_fn(void *extra_state, int complete);
|
|
Packit |
0848f5 |
int cancel_fn(void *extra_state, int complete)
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* This is a very simple test of generalized requests. Normally, the
|
|
Packit |
0848f5 |
* MPI_Grequest_complete function would be called from another routine,
|
|
Packit |
0848f5 |
* often running in a separate thread. This simple code allows us to
|
|
Packit |
0848f5 |
* check that requests can be created, tested, and waited on in the
|
|
Packit |
0848f5 |
* case where the request is complete before the wait is called.
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* Note that MPI did *not* define a routine that can be called within
|
|
Packit |
0848f5 |
* test or wait to advance the state of a generalized request.
|
|
Packit |
0848f5 |
* Most uses of generalized requests will need to use a separate thread.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int errs = 0;
|
|
Packit |
0848f5 |
int counter, flag;
|
|
Packit |
0848f5 |
MPI_Status status;
|
|
Packit |
0848f5 |
MPI_Request request;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Init(&argc, &argv);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Grequest_start(query_fn, free_fn, cancel_fn, NULL, &request);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Test(&request, &flag, &status);
|
|
Packit |
0848f5 |
if (flag) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "Generalized request marked as complete\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Grequest_complete(request);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Wait(&request, &status);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
counter = 1;
|
|
Packit |
0848f5 |
MPI_Grequest_start(query_fn, free_fn, cancel_fn, &counter, &request);
|
|
Packit |
0848f5 |
MPI_Grequest_complete(request);
|
|
Packit |
0848f5 |
MPI_Wait(&request, MPI_STATUS_IGNORE);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (counter) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
fprintf(stderr, "Free routine not called, or not called with extra_data");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Finalize(errs);
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|