📄 ch3u_request.c
字号:
/* -*- Mode: C; c-basic-offset:4 ; -*- *//* * (C) 2001 by Argonne National Laboratory. * See COPYRIGHT in top-level directory. */#include "mpidimpl.h"/* This file contains two types of routines associated with requests: * Routines to allocate and free requests * Routines to manage iovs on requests *//* Routines and data structures for request allocation and deallocation */#ifndef MPID_REQUEST_PREALLOC#define MPID_REQUEST_PREALLOC 8#endifMPID_Request MPID_Request_direct[MPID_REQUEST_PREALLOC] = {{0}};MPIU_Object_alloc_t MPID_Request_mem = { 0, 0, 0, 0, MPID_REQUEST, sizeof(MPID_Request), MPID_Request_direct, MPID_REQUEST_PREALLOC };#undef FUNCNAME#define FUNCNAME MPIDI_CH3_Request_create#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)MPID_Request * MPIDI_CH3_Request_create(){ MPID_Request * req; MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3_REQUEST_CREATE); MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3_REQUEST_CREATE); req = MPIU_Handle_obj_alloc(&MPID_Request_mem); if (req != NULL) { MPIDI_DBG_PRINTF((60, FCNAME, "allocated request, handle=0x%08x", req->handle));# if defined(HAVE_ERROR_CHECKING) { int mpi_errno; if (HANDLE_GET_MPI_KIND(req->handle) != MPID_REQUEST) { mpi_errno = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, FCNAME, __LINE__, MPI_ERR_INTERN, "**invalid_handle", "**invalid_handle %d %p", req->handle, req); MPID_Abort(MPIR_Process.comm_world, mpi_errno, -1, NULL); } }# endif /* FIXME: This is too general; it initializes too much data */ MPIDI_CH3U_Request_create(req); } else { /* FIXME: This fails to fail if debugging is turned off */ MPIDI_DBG_PRINTF((60, FCNAME, "unable to allocate a request")); } MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3_REQUEST_CREATE); return req;}#ifndef MPIDI_CH3_Request_add_ref#undef FUNCNAME#define FUNCNAME MPIDI_CH3_Request_add_ref#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)void MPIDI_CH3_Request_add_ref(MPID_Request * req){ MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3_REQUEST_ADD_REF); MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3_REQUEST_ADD_REF); # if defined(HAVE_ERROR_CHECKING) { if (HANDLE_GET_MPI_KIND(req->handle) != MPID_REQUEST) { int mpi_errno; mpi_errno = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, FCNAME, __LINE__, MPI_ERR_OTHER, "**invalid_handle", "**invalid_handle %d %p", req->handle, req); MPID_Abort(MPIR_Process.comm_world, mpi_errno, -1, NULL); } }# endif MPIU_Object_add_ref(req); # if defined(HAVE_ERROR_CHECKING) { if (req->ref_count < 0) { int mpi_errno; mpi_errno = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, FCNAME, __LINE__, MPI_ERR_OTHER, "**invalid_refcount", "**invalid_refcount %d %p %d", req->handle, req, req->ref_count); MPID_Abort(MPIR_Process.comm_world, mpi_errno, -1, NULL); } }# endif MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3_REQUEST_ADD_REF);}#endif #ifndef MPIDI_CH3_Request_release_ref#undef FUNCNAME#define FUNCNAME MPIDI_CH3_Request_release_ref#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)void MPIDI_CH3_Request_release_ref(MPID_Request * req, int * ref_count){ MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3_REQUEST_RELEASE_REF); MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3_REQUEST_RELEASE_REF);# if defined(HAVE_ERROR_CHECKING) { if (HANDLE_GET_MPI_KIND(req->handle) != MPID_REQUEST) { int mpi_errno; mpi_errno = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, FCNAME, __LINE__, MPI_ERR_OTHER, "**invalid_handle", "**invalid_handle %d %p", req->handle, req); MPID_Abort(MPIR_Process.comm_world, mpi_errno, -1, NULL); } }# endif MPIU_Object_release_ref(req, ref_count); # if defined(HAVE_ERROR_CHECKING) { if (req->ref_count < 0) { int mpi_errno; mpi_errno = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, FCNAME, __LINE__, MPI_ERR_OTHER, "**invalid_refcount", "**invalid_refcount %d %p %d", req->handle, req, req->ref_count); MPID_Abort(MPIR_Process.comm_world, mpi_errno, -1, NULL); } }# endif MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3_REQUEST_RELEASE_REF);}#endif#undef FUNCNAME#define FUNCNAME MPIDI_CH3_Request_destroy#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)void MPIDI_CH3_Request_destroy(MPID_Request * req){ MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3_REQUEST_DESTROY); MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3_REQUEST_DESTROY); MPIDI_DBG_PRINTF((60, FCNAME, "freeing request, handle=0x%08x", req->handle)); # if defined(HAVE_ERROR_CHECKING) { if (HANDLE_GET_MPI_KIND(req->handle) != MPID_REQUEST) { int mpi_errno; mpi_errno = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, FCNAME, __LINE__, MPI_ERR_OTHER, "**invalid_handle", "**invalid_handle %d %p", req->handle, req); MPID_Abort(MPIR_Process.comm_world, mpi_errno, -1, NULL); } if (req->ref_count != 0) { int mpi_errno; mpi_errno = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, FCNAME, __LINE__, MPI_ERR_OTHER, "**invalid_refcount", "**invalid_refcount %d %p %d", req->handle, req, req->ref_count); MPID_Abort(MPIR_Process.comm_world, mpi_errno, -1, NULL); } }# endif if (req->comm != NULL) { MPIR_Comm_release(req->comm); } if (req->dev.datatype_ptr != NULL) { MPID_Datatype_release(req->dev.datatype_ptr); } if (MPIDI_Request_get_srbuf_flag(req)) { MPIDI_CH3U_SRBuf_free(req); } MPID_Request_destruct(req); MPIU_Handle_obj_free(&MPID_Request_mem, req); MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3_REQUEST_DESTROY);}/* ------------------------------------------------------------------------- *//* Here are the routines to manipulate the iovs in the requests *//* ------------------------------------------------------------------------- *//* * MPIDI_CH3U_Request_load_send_iov() * * Fill the provided IOV with the next (or remaining) portion of data described by the segment contained in the request structure. * If the density of IOV is not sufficient, pack the data into a send/receive buffer and point the IOV at the buffer. */#undef FUNCNAME#define FUNCNAME MPIDI_CH3U_Request_load_send_iov#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)int MPIDI_CH3U_Request_load_send_iov(MPID_Request * const sreq, MPID_IOV * const iov, int * const iov_n){ MPIDI_msg_sz_t last; int mpi_errno = MPI_SUCCESS; MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3U_REQUEST_LOAD_SEND_IOV); MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3U_REQUEST_LOAD_SEND_IOV); last = sreq->dev.segment_size; MPIDI_DBG_PRINTF((40, FCNAME, "pre-pv: first=" MPIDI_MSG_SZ_FMT ", last=" MPIDI_MSG_SZ_FMT ", iov_n=%d", sreq->dev.segment_first, last, *iov_n)); MPIU_Assert(sreq->dev.segment_first < last); MPIU_Assert(last > 0); MPIU_Assert(*iov_n > 0 && *iov_n <= MPID_IOV_LIMIT); MPID_Segment_pack_vector(&sreq->dev.segment, sreq->dev.segment_first, &last, iov, iov_n); MPIDI_DBG_PRINTF((40, FCNAME, "post-pv: first=" MPIDI_MSG_SZ_FMT ", last=" MPIDI_MSG_SZ_FMT ", iov_n=%d", sreq->dev.segment_first, last, *iov_n)); MPIU_Assert(*iov_n > 0 && *iov_n <= MPID_IOV_LIMIT); if (last == sreq->dev.segment_size) { MPIDI_DBG_PRINTF((40, FCNAME, "remaining data loaded into IOV")); sreq->dev.ca = MPIDI_CH3_CA_COMPLETE; } else if ((last - sreq->dev.segment_first) / *iov_n >= MPIDI_IOV_DENSITY_MIN) { MPIDI_DBG_PRINTF((40, FCNAME, "more data loaded into IOV")); sreq->dev.segment_first = last; sreq->dev.ca = MPIDI_CH3_CA_RELOAD_IOV; } else { MPIDI_msg_sz_t data_sz; MPIDI_DBG_PRINTF((40, FCNAME, "low density. using SRBuf.")); data_sz = sreq->dev.segment_size - sreq->dev.segment_first; if (!MPIDI_Request_get_srbuf_flag(sreq)) { MPIDI_CH3U_SRBuf_alloc(sreq, data_sz); /* --BEGIN ERROR HANDLING-- */ if (sreq->dev.tmpbuf_sz == 0) { MPIDI_DBG_PRINTF((40, FCNAME, "SRBuf allocation failure")); mpi_errno = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, FCNAME, __LINE__, MPI_ERR_OTHER, "**nomem", 0); sreq->status.MPI_ERROR = mpi_errno; goto fn_exit; } /* --END ERROR HANDLING-- */ } last = (data_sz <= sreq->dev.tmpbuf_sz) ? sreq->dev.segment_size : sreq->dev.segment_first + sreq->dev.tmpbuf_sz; MPIDI_DBG_PRINTF((40, FCNAME, "pre-pack: first=" MPIDI_MSG_SZ_FMT ", last=" MPIDI_MSG_SZ_FMT, sreq->dev.segment_first, last)); MPID_Segment_pack(&sreq->dev.segment, sreq->dev.segment_first, &last, sreq->dev.tmpbuf); MPIDI_DBG_PRINTF((40, FCNAME, "post-pack: first=" MPIDI_MSG_SZ_FMT ", last=" MPIDI_MSG_SZ_FMT, sreq->dev.segment_first, last)); iov[0].MPID_IOV_BUF = (MPID_IOV_BUF_CAST)sreq->dev.tmpbuf; iov[0].MPID_IOV_LEN = last - sreq->dev.segment_first; *iov_n = 1; if (last == sreq->dev.segment_size) { MPIDI_DBG_PRINTF((40, FCNAME, "remaining data packed into SRBuf")); sreq->dev.ca = MPIDI_CH3_CA_COMPLETE; } else { MPIDI_DBG_PRINTF((40, FCNAME, "more data packed into SRBuf")); sreq->dev.segment_first = last; sreq->dev.ca = MPIDI_CH3_CA_RELOAD_IOV; } } fn_exit: MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3U_REQUEST_LOAD_SEND_IOV); return mpi_errno;}/* * MPIDI_CH3U_Request_load_recv_iov() *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -