Skip to content

Commit 74049fc

Browse files
committed
Expose opal_datatype_compute_remote_size.
This function can be used to compute the packed size of a datatype on a target architecture. Signed-off-by: George Bosilca <[email protected]>
1 parent 0041ce8 commit 74049fc

File tree

3 files changed

+36
-26
lines changed

3 files changed

+36
-26
lines changed

opal/datatype/opal_convertor.c

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -455,29 +455,6 @@ int32_t opal_convertor_set_position_nocheck(opal_convertor_t *convertor, size_t
455455
return rc;
456456
}
457457

458-
static size_t opal_datatype_compute_remote_size(const opal_datatype_t *pData, const size_t *sizes)
459-
{
460-
uint32_t typeMask = pData->bdt_used;
461-
size_t length = 0;
462-
463-
if (opal_datatype_is_predefined(pData)) {
464-
return sizes[pData->desc.desc->elem.common.type];
465-
}
466-
467-
if (OPAL_UNLIKELY(NULL == pData->ptypes)) {
468-
/* Allocate and fill the array of types used in the datatype description */
469-
opal_datatype_compute_ptypes((opal_datatype_t *) pData);
470-
}
471-
472-
for (int i = OPAL_DATATYPE_FIRST_TYPE; typeMask && (i < OPAL_DATATYPE_MAX_PREDEFINED); i++) {
473-
if (typeMask & ((uint32_t) 1 << i)) {
474-
length += (pData->ptypes[i] * sizes[i]);
475-
typeMask ^= ((uint32_t) 1 << i);
476-
}
477-
}
478-
return length;
479-
}
480-
481458
/**
482459
* Compute the remote size. If necessary remove the homogeneous flag
483460
* and redirect the convertor description toward the non-optimized
@@ -496,9 +473,9 @@ size_t opal_convertor_compute_remote_size(opal_convertor_t *pConvertor)
496473
}
497474
if (0 == (pConvertor->flags & CONVERTOR_HAS_REMOTE_SIZE)) {
498475
/* This is for a single datatype, we must update it with the count */
499-
pConvertor->remote_size = opal_datatype_compute_remote_size(datatype,
500-
pConvertor->master
501-
->remote_sizes);
476+
pConvertor->remote_size =
477+
opal_datatype_compute_remote_size(datatype,
478+
pConvertor->master->remote_sizes);
502479
pConvertor->remote_size *= pConvertor->count;
503480
}
504481
}

opal/datatype/opal_datatype.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,15 @@ OPAL_DECLSPEC int32_t opal_datatype_copy_content_same_ddt(const opal_datatype_t
311311

312312
OPAL_DECLSPEC int opal_datatype_compute_ptypes(opal_datatype_t *datatype);
313313

314+
/*
315+
* Compute the size of the datatype using a specific set of predefined type sizes.
316+
* This function allows to compute the size of a packed buffer without creating
317+
* a fully fledged specialized convertor for the remote peer.
318+
*/
319+
OPAL_DECLSPEC size_t
320+
opal_datatype_compute_remote_size(const opal_datatype_t *pData,
321+
const size_t *sizes);
322+
314323
/* Compute the span in memory of count datatypes. This function help with temporary
315324
* memory allocations for receiving already typed data (such as those used for reduce
316325
* operations). This span is the distance between the minimum and the maximum byte

opal/datatype/opal_datatype_get_count.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,27 @@ int opal_datatype_compute_ptypes(opal_datatype_t *datatype)
223223
}
224224
}
225225
}
226+
227+
size_t opal_datatype_compute_remote_size(const opal_datatype_t *pData, const size_t *sizes)
228+
{
229+
uint32_t typeMask = pData->bdt_used;
230+
size_t length = 0;
231+
232+
if (opal_datatype_is_predefined(pData)) {
233+
return sizes[pData->desc.desc->elem.common.type];
234+
}
235+
236+
if (OPAL_UNLIKELY(NULL == pData->ptypes)) {
237+
/* Allocate and fill the array of types used in the datatype description */
238+
opal_datatype_compute_ptypes((opal_datatype_t *) pData);
239+
}
240+
241+
for (int i = OPAL_DATATYPE_FIRST_TYPE; typeMask && (i < OPAL_DATATYPE_MAX_PREDEFINED); i++) {
242+
if (typeMask & ((uint32_t) 1 << i)) {
243+
length += (pData->ptypes[i] * sizes[i]);
244+
typeMask ^= ((uint32_t) 1 << i);
245+
}
246+
}
247+
return length;
248+
}
249+

0 commit comments

Comments
 (0)