2014-11-20 09:22:43 +03:00
|
|
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 Sandia National Laboratories. All rights reserved.
|
|
|
|
* Copyright (c) 2014 Los Alamos National Security, LLC. All rights
|
|
|
|
* reserved.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2014-11-05 19:59:12 +03:00
|
|
|
#ifndef OSC_PT2PT_FRAG_H
|
|
|
|
#define OSC_PT2PT_FRAG_H
|
2014-11-20 09:22:43 +03:00
|
|
|
|
|
|
|
#include "ompi/communicator/communicator.h"
|
|
|
|
|
2014-11-05 19:59:12 +03:00
|
|
|
#include "osc_pt2pt_header.h"
|
|
|
|
#include "osc_pt2pt_request.h"
|
2014-11-20 09:22:43 +03:00
|
|
|
#include "opal/align.h"
|
|
|
|
|
|
|
|
/** Communication buffer for packing messages */
|
2014-11-05 19:59:12 +03:00
|
|
|
struct ompi_osc_pt2pt_frag_t {
|
2014-11-14 01:13:10 +03:00
|
|
|
ompi_free_list_item_t super;
|
2014-11-20 09:22:43 +03:00
|
|
|
/* target rank of buffer */
|
|
|
|
int target;
|
|
|
|
unsigned char *buffer;
|
|
|
|
|
|
|
|
/* space remaining in buffer */
|
|
|
|
size_t remain_len;
|
|
|
|
|
|
|
|
/* start of unused space */
|
|
|
|
char *top;
|
|
|
|
|
|
|
|
/* Number of operations which have started writing into the frag, but not yet completed doing so */
|
2014-11-14 01:13:10 +03:00
|
|
|
int32_t pending;
|
2014-11-05 19:59:12 +03:00
|
|
|
ompi_osc_pt2pt_frag_header_t *header;
|
|
|
|
ompi_osc_pt2pt_module_t *module;
|
2014-11-20 09:22:43 +03:00
|
|
|
};
|
2014-11-05 19:59:12 +03:00
|
|
|
typedef struct ompi_osc_pt2pt_frag_t ompi_osc_pt2pt_frag_t;
|
|
|
|
OBJ_CLASS_DECLARATION(ompi_osc_pt2pt_frag_t);
|
2014-11-20 09:22:43 +03:00
|
|
|
|
2014-11-05 19:59:12 +03:00
|
|
|
extern int ompi_osc_pt2pt_frag_start(ompi_osc_pt2pt_module_t *module, ompi_osc_pt2pt_frag_t *buffer);
|
|
|
|
extern int ompi_osc_pt2pt_frag_flush_target(ompi_osc_pt2pt_module_t *module, int target);
|
|
|
|
extern int ompi_osc_pt2pt_frag_flush_all(ompi_osc_pt2pt_module_t *module);
|
2014-11-20 09:22:43 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: module lock must be held during this operation
|
|
|
|
*/
|
2014-11-05 19:59:12 +03:00
|
|
|
static inline int ompi_osc_pt2pt_frag_alloc(ompi_osc_pt2pt_module_t *module, int target,
|
|
|
|
size_t request_len, ompi_osc_pt2pt_frag_t **buffer,
|
2014-11-20 09:22:43 +03:00
|
|
|
char **ptr)
|
|
|
|
{
|
2014-11-05 19:59:12 +03:00
|
|
|
ompi_osc_pt2pt_frag_t *curr = module->peers[target].active_frag;
|
2014-11-20 09:22:43 +03:00
|
|
|
int ret;
|
|
|
|
|
2014-11-05 19:59:12 +03:00
|
|
|
/* osc pt2pt headers can have 64-bit values. these will need to be aligned
|
2014-11-20 09:22:43 +03:00
|
|
|
* on an 8-byte boundary on some architectures so we up align the allocation
|
|
|
|
* size here. */
|
|
|
|
request_len = OPAL_ALIGN(request_len, 8, size_t);
|
|
|
|
|
2014-11-05 19:59:12 +03:00
|
|
|
if (request_len > mca_osc_pt2pt_component.buffer_size) {
|
2014-11-20 09:22:43 +03:00
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
|
2014-11-14 01:13:10 +03:00
|
|
|
OPAL_THREAD_LOCK(&module->lock);
|
2014-11-20 09:22:43 +03:00
|
|
|
if (NULL == curr || curr->remain_len < request_len) {
|
2014-11-14 01:13:10 +03:00
|
|
|
ompi_free_list_item_t *item = NULL;
|
2014-11-20 09:22:43 +03:00
|
|
|
|
|
|
|
if (NULL != curr) {
|
|
|
|
curr->remain_len = 0;
|
2014-11-14 01:13:10 +03:00
|
|
|
module->peers[target].active_frag = NULL;
|
|
|
|
opal_atomic_mb ();
|
|
|
|
|
2014-11-20 09:22:43 +03:00
|
|
|
/* If there's something pending, the pending finish will
|
|
|
|
start the buffer. Otherwise, we need to start it now. */
|
2014-11-14 01:13:10 +03:00
|
|
|
if (0 == OPAL_THREAD_ADD32(&curr->pending, -1)) {
|
2014-11-05 19:59:12 +03:00
|
|
|
ret = ompi_osc_pt2pt_frag_start(module, curr);
|
2014-11-14 01:13:10 +03:00
|
|
|
if (OPAL_UNLIKELY(OMPI_SUCCESS != ret)) {
|
|
|
|
return ret;
|
|
|
|
}
|
2014-11-20 09:22:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-14 01:13:10 +03:00
|
|
|
OMPI_FREE_LIST_GET_MT(&mca_osc_pt2pt_component.frags, item);
|
|
|
|
if (OPAL_UNLIKELY(NULL == item)) {
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2014-11-20 09:22:43 +03:00
|
|
|
curr = module->peers[target].active_frag =
|
2014-11-05 19:59:12 +03:00
|
|
|
(ompi_osc_pt2pt_frag_t*) item;
|
2014-11-20 09:22:43 +03:00
|
|
|
|
|
|
|
curr->target = target;
|
|
|
|
|
2014-11-05 19:59:12 +03:00
|
|
|
curr->header = (ompi_osc_pt2pt_frag_header_t*) curr->buffer;
|
2014-11-20 09:22:43 +03:00
|
|
|
curr->top = (char*) (curr->header + 1);
|
2014-11-05 19:59:12 +03:00
|
|
|
curr->remain_len = mca_osc_pt2pt_component.buffer_size;
|
2014-11-20 09:22:43 +03:00
|
|
|
curr->module = module;
|
2014-11-14 01:13:10 +03:00
|
|
|
curr->pending = 1;
|
2014-11-20 09:22:43 +03:00
|
|
|
|
2014-11-05 19:59:12 +03:00
|
|
|
curr->header->base.type = OMPI_OSC_PT2PT_HDR_TYPE_FRAG;
|
|
|
|
curr->header->base.flags = OMPI_OSC_PT2PT_HDR_FLAG_VALID;
|
2014-11-20 09:22:43 +03:00
|
|
|
if (module->passive_target_access_epoch) {
|
2014-11-05 19:59:12 +03:00
|
|
|
curr->header->base.flags |= OMPI_OSC_PT2PT_HDR_FLAG_PASSIVE_TARGET;
|
2014-11-20 09:22:43 +03:00
|
|
|
}
|
|
|
|
curr->header->source = ompi_comm_rank(module->comm);
|
|
|
|
curr->header->num_ops = 0;
|
|
|
|
curr->header->windx = ompi_comm_get_cid(module->comm);
|
|
|
|
|
|
|
|
if (curr->remain_len < request_len) {
|
2014-11-14 01:13:10 +03:00
|
|
|
OPAL_THREAD_UNLOCK(&module->lock);
|
2014-11-20 09:22:43 +03:00
|
|
|
return OMPI_ERR_TEMP_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*ptr = curr->top;
|
|
|
|
*buffer = curr;
|
|
|
|
|
|
|
|
curr->top += request_len;
|
|
|
|
curr->remain_len -= request_len;
|
2014-11-14 01:13:10 +03:00
|
|
|
OPAL_THREAD_UNLOCK(&module->lock);
|
|
|
|
|
|
|
|
OPAL_THREAD_ADD32(&curr->pending, 1);
|
|
|
|
OPAL_THREAD_ADD32(&curr->header->num_ops, 1);
|
2014-11-20 09:22:43 +03:00
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: module lock must be held for this operation
|
|
|
|
*/
|
2014-11-05 19:59:12 +03:00
|
|
|
static inline int ompi_osc_pt2pt_frag_finish(ompi_osc_pt2pt_module_t *module,
|
|
|
|
ompi_osc_pt2pt_frag_t* buffer)
|
2014-11-20 09:22:43 +03:00
|
|
|
{
|
2014-11-14 01:13:10 +03:00
|
|
|
if (0 == OPAL_THREAD_ADD32(&buffer->pending, -1)) {
|
2014-11-05 19:59:12 +03:00
|
|
|
return ompi_osc_pt2pt_frag_start(module, buffer);
|
2014-11-20 09:22:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|