Skip to content

Commit 1a17cb3

Browse files
committed
opal/datatype: add opal_datatype_is_monotonic()
return true if the datatype has non-negative displacements and monotonically nondecreasing, and false otherwise. Thanks George for the guidance. Signed-off-by: Gilles Gouaillardet <[email protected]>
1 parent b6840ad commit 1a17cb3

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

opal/datatype/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
1616
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
1717
# Copyright (c) 2011-2013 NVIDIA Corporation. All rights reserved.
18+
# Copyright (c) 2018 Research Organization for Information Science
19+
# and Technology (RIST). All rights reserved.
1820
# $COPYRIGHT$
1921
#
2022
# Additional copyrights may follow
@@ -59,6 +61,7 @@ libdatatype_la_SOURCES = \
5961
opal_datatype_fake_stack.c \
6062
opal_datatype_get_count.c \
6163
opal_datatype_module.c \
64+
opal_datatype_monotonic.c \
6265
opal_datatype_optimize.c \
6366
opal_datatype_pack.c \
6467
opal_datatype_position.c \

opal/datatype/opal_datatype.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* reserved.
1515
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
1616
* Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
17-
* Copyright (c) 2017 Research Organization for Information Science
17+
* Copyright (c) 2017-2018 Research Organization for Information Science
1818
* and Technology (RIST). All rights reserved.
1919
* $COPYRIGHT$
2020
*
@@ -186,6 +186,7 @@ OPAL_DECLSPEC opal_datatype_t* opal_datatype_create( int32_t expectedSize );
186186
OPAL_DECLSPEC int32_t opal_datatype_create_desc( opal_datatype_t * datatype, int32_t expectedSize );
187187
OPAL_DECLSPEC int32_t opal_datatype_commit( opal_datatype_t * pData );
188188
OPAL_DECLSPEC int32_t opal_datatype_destroy( opal_datatype_t** );
189+
OPAL_DECLSPEC int32_t opal_datatype_is_monotonic( opal_datatype_t* type);
189190

190191
static inline int32_t
191192
opal_datatype_is_committed( const opal_datatype_t* type )
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; -*- */
2+
/*
3+
* Copyright (c) 2018 Research Organization for Information Science
4+
* and Technology (RIST). All rights reserved.
5+
* $COPYRIGHT$
6+
*
7+
* Additional copyrights may follow
8+
*
9+
* $HEADER$
10+
*/
11+
12+
#include "opal_config.h"
13+
14+
#include <stddef.h>
15+
16+
#include "opal/constants.h"
17+
#include "opal/datatype/opal_datatype.h"
18+
#include "opal/datatype/opal_datatype_internal.h"
19+
#include "opal/datatype/opal_convertor.h"
20+
21+
int32_t opal_datatype_is_monotonic(opal_datatype_t* type )
22+
{
23+
opal_convertor_t *pConv;
24+
uint32_t iov_count;
25+
struct iovec iov[5];
26+
size_t max_data = 0;
27+
long prev = -1;
28+
int rc;
29+
bool monotonic = true;
30+
31+
pConv = opal_convertor_create( opal_local_arch, 0 );
32+
if (OPAL_UNLIKELY(NULL == pConv)) {
33+
return 0;
34+
}
35+
rc = opal_convertor_prepare_for_send( pConv, type, 1, NULL );
36+
if( OPAL_UNLIKELY(OPAL_SUCCESS != rc)) {
37+
OBJ_RELEASE(pConv);
38+
return 0;
39+
}
40+
41+
do {
42+
iov_count = 5;
43+
rc = opal_convertor_raw( pConv, iov, &iov_count, &max_data);
44+
for (uint32_t i=0; i<iov_count; i++) {
45+
if ((long)iov[i].iov_base < prev) {
46+
monotonic = false;
47+
goto cleanup;
48+
}
49+
prev = (long)iov[i].iov_base;
50+
}
51+
} while (rc != 1);
52+
53+
cleanup:
54+
OBJ_RELEASE( pConv );
55+
56+
return monotonic;
57+
}

0 commit comments

Comments
 (0)