![Aurelien Bouteiller](/assets/img/avatar_default.png)
A new global structure (ompi_request_functions) holding all the pointers to the wait/test functions have been added. ompi_request_wait* and ompi_request_test* have been #defined to be replaced by ompi_request_functions.req_wait. The default implementations of the wait/test functions names have been changed from ompi_request_% to ompi_request_default_%. Those functions are static initializer of the ompi_request_functions structure. To modify the defaults, a components 1) copy the ompi_request_functions structure (the type ompi_request_fns_t can be used to declare a suitable variable), 2) change some of the functions according to its needs. This is best done at MPI_init time when there is no threads. Should this component be unloaded it have to restore the defaults. The ompi_request_default_* functions should never be called directly anywhere in the code. If a component needs to access the previously defined implementation of wait, it should call its local copy of the function. Component implementors should keep in mind that another component might have already changed the defaults and needs to be called. This commit was SVN r16862.
174 строки
5.9 KiB
C
174 строки
5.9 KiB
C
/*
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
* University Research and Technology
|
|
* Corporation. All rights reserved.
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
|
* of Tennessee Research Foundation. All rights
|
|
* reserved.
|
|
* Copyright (c) 2004-2007 High Performance Computing Center Stuttgart,
|
|
* University of Stuttgart. All rights reserved.
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
* All rights reserved.
|
|
* Copyright (c) 2006 Cisco Systems, Inc. All rights reserved.
|
|
* $COPYRIGHT$
|
|
*
|
|
* Additional copyrights may follow
|
|
*
|
|
* $HEADER$
|
|
*/
|
|
|
|
#include "ompi_config.h"
|
|
|
|
#include "opal/class/opal_object.h"
|
|
#include "ompi/request/request.h"
|
|
#include "ompi/request/request_default.h"
|
|
#include "ompi/constants.h"
|
|
|
|
ompi_pointer_array_t ompi_request_f_to_c_table;
|
|
size_t ompi_request_waiting = 0;
|
|
size_t ompi_request_completed = 0;
|
|
opal_mutex_t ompi_request_lock;
|
|
opal_condition_t ompi_request_cond;
|
|
ompi_request_t ompi_request_null;
|
|
ompi_request_t ompi_request_empty;
|
|
ompi_status_public_t ompi_status_empty;
|
|
ompi_request_fns_t ompi_request_functions = {
|
|
ompi_request_default_test,
|
|
ompi_request_default_test_any,
|
|
ompi_request_default_test_all,
|
|
ompi_request_default_test_some,
|
|
ompi_request_default_wait,
|
|
ompi_request_default_wait_any,
|
|
ompi_request_default_wait_all,
|
|
ompi_request_default_wait_some
|
|
};
|
|
|
|
static void ompi_request_construct(ompi_request_t* req)
|
|
{
|
|
OMPI_REQUEST_INIT(req, false);
|
|
req->req_free = NULL;
|
|
req->req_cancel = NULL;
|
|
req->req_f_to_c_index = MPI_UNDEFINED;
|
|
req->req_mpi_object.comm = (struct ompi_communicator_t*) NULL;
|
|
}
|
|
|
|
static void ompi_request_destruct(ompi_request_t* req)
|
|
{
|
|
assert( MPI_UNDEFINED == req->req_f_to_c_index );
|
|
assert( OMPI_REQUEST_INVALID == req->req_state );
|
|
}
|
|
|
|
static int ompi_request_null_free(ompi_request_t** request)
|
|
{
|
|
return OMPI_SUCCESS;
|
|
}
|
|
|
|
static int ompi_request_null_cancel(ompi_request_t* request, int flag)
|
|
{
|
|
return OMPI_SUCCESS;
|
|
}
|
|
|
|
static int ompi_request_empty_free(ompi_request_t** request)
|
|
{
|
|
*request = &ompi_request_null;
|
|
return OMPI_SUCCESS;
|
|
}
|
|
|
|
int ompi_request_persistent_proc_null_free(ompi_request_t** request)
|
|
{
|
|
OMPI_REQUEST_FINI(*request);
|
|
(*request)->req_state = OMPI_REQUEST_INVALID;
|
|
OBJ_RELEASE(*request);
|
|
*request = &ompi_request_null;
|
|
return OMPI_SUCCESS;
|
|
}
|
|
|
|
|
|
OBJ_CLASS_INSTANCE(
|
|
ompi_request_t,
|
|
ompi_free_list_item_t,
|
|
ompi_request_construct,
|
|
ompi_request_destruct);
|
|
|
|
|
|
int ompi_request_init(void)
|
|
{
|
|
OBJ_CONSTRUCT(&ompi_request_f_to_c_table, ompi_pointer_array_t);
|
|
OBJ_CONSTRUCT(&ompi_request_lock, opal_mutex_t);
|
|
OBJ_CONSTRUCT(&ompi_request_cond, opal_condition_t);
|
|
|
|
OBJ_CONSTRUCT(&ompi_request_null, ompi_request_t);
|
|
ompi_request_null.req_type = OMPI_REQUEST_NULL;
|
|
ompi_request_null.req_status.MPI_SOURCE = MPI_PROC_NULL;
|
|
ompi_request_null.req_status.MPI_TAG = MPI_ANY_TAG;
|
|
ompi_request_null.req_status.MPI_ERROR = MPI_SUCCESS;
|
|
ompi_request_null.req_status._count = 0;
|
|
ompi_request_null.req_status._cancelled = 0;
|
|
|
|
ompi_request_null.req_complete = true;
|
|
ompi_request_null.req_state = OMPI_REQUEST_INACTIVE;
|
|
ompi_request_null.req_persistent = false;
|
|
ompi_request_null.req_f_to_c_index =
|
|
ompi_pointer_array_add(&ompi_request_f_to_c_table, &ompi_request_null);
|
|
ompi_request_null.req_free = ompi_request_null_free;
|
|
ompi_request_null.req_cancel = ompi_request_null_cancel;
|
|
ompi_request_null.req_mpi_object.comm = &ompi_mpi_comm_world;
|
|
|
|
if (0 != ompi_request_null.req_f_to_c_index) {
|
|
return OMPI_ERR_REQUEST;
|
|
}
|
|
|
|
/* We need a way to distinguish between the user provided
|
|
* MPI_REQUEST_NULL to MPI_Wait* and a non-active (MPI_PROC_NULL)
|
|
* request passed to any P2P non-blocking function.
|
|
*
|
|
* The main difference to ompi_request_null is
|
|
* req_state being OMPI_REQUEST_ACTIVE, so that MPI_Waitall
|
|
* does not set the status to ompi_status_empty and the different
|
|
* req_free function, which resets the
|
|
* request to MPI_REQUEST_NULL.
|
|
* The req_cancel function need not be changed.
|
|
*/
|
|
OBJ_CONSTRUCT(&ompi_request_empty, ompi_request_t);
|
|
ompi_request_empty.req_type = OMPI_REQUEST_NULL;
|
|
ompi_request_empty.req_status.MPI_SOURCE = MPI_PROC_NULL;
|
|
ompi_request_empty.req_status.MPI_TAG = MPI_ANY_TAG;
|
|
ompi_request_empty.req_status.MPI_ERROR = MPI_SUCCESS;
|
|
ompi_request_empty.req_status._count = 0;
|
|
ompi_request_empty.req_status._cancelled = 0;
|
|
|
|
ompi_request_empty.req_complete = true;
|
|
ompi_request_empty.req_state = OMPI_REQUEST_ACTIVE;
|
|
ompi_request_empty.req_persistent = false;
|
|
ompi_request_empty.req_f_to_c_index =
|
|
ompi_pointer_array_add(&ompi_request_f_to_c_table, &ompi_request_empty);
|
|
ompi_request_empty.req_free = ompi_request_empty_free;
|
|
ompi_request_empty.req_cancel = ompi_request_null_cancel;
|
|
ompi_request_empty.req_mpi_object.comm = &ompi_mpi_comm_world;
|
|
|
|
if (1 != ompi_request_empty.req_f_to_c_index) {
|
|
return OMPI_ERR_REQUEST;
|
|
}
|
|
|
|
ompi_status_empty.MPI_SOURCE = MPI_ANY_SOURCE;
|
|
ompi_status_empty.MPI_TAG = MPI_ANY_TAG;
|
|
ompi_status_empty.MPI_ERROR = MPI_SUCCESS;
|
|
ompi_status_empty._count = 0;
|
|
ompi_status_empty._cancelled = 0;
|
|
|
|
return OMPI_SUCCESS;
|
|
}
|
|
|
|
|
|
int ompi_request_finalize(void)
|
|
{
|
|
OMPI_REQUEST_FINI( &ompi_request_null );
|
|
OBJ_DESTRUCT( &ompi_request_null );
|
|
OMPI_REQUEST_FINI( &ompi_request_empty );
|
|
OBJ_DESTRUCT( &ompi_request_empty );
|
|
OBJ_DESTRUCT( &ompi_request_cond );
|
|
OBJ_DESTRUCT( &ompi_request_lock );
|
|
OBJ_DESTRUCT( &ompi_request_f_to_c_table );
|
|
return OMPI_SUCCESS;
|
|
}
|