Skip to content

Commit c1b1bfc

Browse files
Merge pull request #4684 from ggouaillardet/topic/monotonic_datatype
MPI_File_set_view(): check datatypes are monotonic
2 parents b6840ad + 02f8215 commit c1b1bfc

File tree

8 files changed

+107
-11
lines changed

8 files changed

+107
-11
lines changed

ompi/datatype/ompi_datatype.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2010-2017 Cisco Systems, Inc. All rights reserved
88
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
99
* reserved.
10-
* Copyright (c) 2015-2017 Research Organization for Information Science
10+
* Copyright (c) 2015-2018 Research Organization for Information Science
1111
* and Technology (RIST). All rights reserved.
1212
* $COPYRIGHT$
1313
*
@@ -44,6 +44,8 @@ BEGIN_C_DECLS
4444
/* These flags are on top of the flags in opal_datatype.h */
4545
/* Is the datatype predefined as MPI type (not necessarily as OPAL type, e.g. struct/block types) */
4646
#define OMPI_DATATYPE_FLAG_PREDEFINED 0x0200
47+
#define OMPI_DATATYPE_FLAG_ANALYZED 0x0400
48+
#define OMPI_DATATYPE_FLAG_MONOTONIC 0x0800
4749
/* Keep trace of the type of the predefined datatypes */
4850
#define OMPI_DATATYPE_FLAG_DATA_INT 0x1000
4951
#define OMPI_DATATYPE_FLAG_DATA_FLOAT 0x2000
@@ -152,13 +154,23 @@ ompi_datatype_is_contiguous_memory_layout( const ompi_datatype_t* type, int32_t
152154
return opal_datatype_is_contiguous_memory_layout(&type->super, count);
153155
}
154156

157+
static inline int32_t
158+
ompi_datatype_is_monotonic( ompi_datatype_t * type ) {
159+
if (!(type->super.flags & OMPI_DATATYPE_FLAG_ANALYZED)) {
160+
if (opal_datatype_is_monotonic(&type->super)) {
161+
type->super.flags |= OMPI_DATATYPE_FLAG_MONOTONIC;
162+
}
163+
type->super.flags |= OMPI_DATATYPE_FLAG_ANALYZED;
164+
}
165+
return type->super.flags & OMPI_DATATYPE_FLAG_MONOTONIC;
166+
}
167+
155168
static inline int32_t
156169
ompi_datatype_commit( ompi_datatype_t ** type )
157170
{
158171
return opal_datatype_commit ( (opal_datatype_t*)*type );
159172
}
160173

161-
162174
OMPI_DECLSPEC int32_t ompi_datatype_destroy( ompi_datatype_t** type);
163175

164176

ompi/datatype/ompi_datatype_internal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2010-2012 Cisco Systems, Inc. All rights reserved.
88
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
99
* reserved.
10-
* Copyright (c) 2015-2017 Research Organization for Information Science
10+
* Copyright (c) 2015-2018 Research Organization for Information Science
1111
* and Technology (RIST). All rights reserved.
1212
* Copyright (c) 2016 FUJITSU LIMITED. All rights reserved.
1313
* $COPYRIGHT$
@@ -416,6 +416,8 @@ extern const ompi_datatype_t* ompi_datatype_basicDatatypes[OMPI_DATATYPE_MPI_MAX
416416
{ /*ompi_predefined_datatype_t*/ \
417417
{ /* ompi_datatype_t */ \
418418
OMPI_DATATYPE_INITIALIZER_ ## TYPE (OMPI_DATATYPE_FLAG_PREDEFINED | \
419+
OMPI_DATATYPE_FLAG_ANALYZED | \
420+
OMPI_DATATYPE_FLAG_MONOTONIC | \
419421
(FLAGS)) /*super*/, \
420422
OMPI_DATATYPE_EMPTY_DATA(NAME) /*id,d_f_to_c_index,d_keyhash,args,packed_description,name*/ \
421423
}, \
@@ -457,6 +459,8 @@ extern const ompi_datatype_t* ompi_datatype_basicDatatypes[OMPI_DATATYPE_MPI_MAX
457459
.super = OPAL_OBJ_STATIC_INIT(opal_datatype_t), \
458460
.flags = OPAL_DATATYPE_FLAG_BASIC | \
459461
OMPI_DATATYPE_FLAG_PREDEFINED | \
462+
OMPI_DATATYPE_FLAG_ANALYZED | \
463+
OMPI_DATATYPE_FLAG_MONOTONIC | \
460464
OMPI_DATATYPE_FLAG_DATA_FORTRAN | (FLAGS), \
461465
.id = OPAL_DATATYPE_ ## TYPE ## SIZE, \
462466
.bdt_used = (((uint32_t)1)<<(OPAL_DATATYPE_ ## TYPE ## SIZE)), \

ompi/datatype/ompi_datatype_module.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
1616
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
1717
* reserved.
18-
* Copyright (c) 2015-2017 Research Organization for Information Science
18+
* Copyright (c) 2015-2018 Research Organization for Information Science
1919
* and Technology (RIST). All rights reserved.
2020
* Copyright (c) 2016 FUJITSU LIMITED. All rights reserved.
2121
* $COPYRIGHT$
@@ -414,7 +414,9 @@ opal_pointer_array_t ompi_datatype_f_to_c_table = {{0}};
414414
ompi_datatype_commit( &ptype ); \
415415
COPY_DATA_DESC( PDATA, ptype ); \
416416
(PDATA)->super.flags &= ~OPAL_DATATYPE_FLAG_PREDEFINED; \
417-
(PDATA)->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED; \
417+
(PDATA)->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED | \
418+
OMPI_DATATYPE_FLAG_ANALYZED | \
419+
OMPI_DATATYPE_FLAG_MONOTONIC; \
418420
ptype->super.desc.desc = NULL; \
419421
ptype->super.opt_desc.desc = NULL; \
420422
OBJ_RELEASE( ptype ); \
@@ -430,7 +432,9 @@ opal_pointer_array_t ompi_datatype_f_to_c_table = {{0}};
430432
ompi_datatype_commit( &ptype ); \
431433
COPY_DATA_DESC( (PDATA), ptype ); \
432434
(PDATA)->super.flags &= ~OPAL_DATATYPE_FLAG_PREDEFINED; \
433-
(PDATA)->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED; \
435+
(PDATA)->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED | \
436+
OMPI_DATATYPE_FLAG_ANALYZED | \
437+
OMPI_DATATYPE_FLAG_MONOTONIC; \
434438
ptype->super.desc.desc = NULL; \
435439
ptype->super.opt_desc.desc = NULL; \
436440
OBJ_RELEASE( ptype ); \
@@ -445,7 +449,9 @@ opal_pointer_array_t ompi_datatype_f_to_c_table = {{0}};
445449
/* forget the language flag */ \
446450
(PDATA)->super.flags &= ~OMPI_DATATYPE_FLAG_DATA_LANGUAGE; \
447451
(PDATA)->super.flags &= ~OPAL_DATATYPE_FLAG_PREDEFINED; \
448-
(PDATA)->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED; \
452+
(PDATA)->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED | \
453+
OMPI_DATATYPE_FLAG_ANALYZED | \
454+
OMPI_DATATYPE_FLAG_MONOTONIC; \
449455
} while(0)
450456

451457

ompi/mpi/c/bindings.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
1212
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
13+
* Copyright (c) 2018 Research Organization for Information Science
14+
* and Technology (RIST). All rights reserved.
1315
* $COPYRIGHT$
1416
*
1517
* Additional copyrights may follow
@@ -71,6 +73,17 @@ BEGIN_C_DECLS
7173
else if( !opal_datatype_is_valid(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
7274
} while(0)
7375

76+
#define OMPI_CHECK_DATATYPE_FOR_VIEW( RC, DDT, COUNT ) \
77+
do { \
78+
/* (RC) = MPI_SUCCESS; */ \
79+
if( NULL == (DDT) || MPI_DATATYPE_NULL == (DDT) ) (RC) = MPI_ERR_TYPE; \
80+
else if( (COUNT) < 0 ) (RC) = MPI_ERR_COUNT; \
81+
else if( !opal_datatype_is_committed(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
82+
/* XXX Fix flags else if( ompi_datatype_is_overlapped((DDT)) ) (RC) = MPI_ERR_TYPE; */ \
83+
else if( !opal_datatype_is_valid(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
84+
else if( !ompi_datatype_is_monotonic((DDT)) ) (RC) = MPI_ERR_TYPE; \
85+
} while (0)
86+
7487

7588
/* This macro has to be used to check the correctness of the user buffer depending on the datatype.
7689
* This macro expects that the DDT parameter is a valid pointer to an ompi datatype object.

ompi/mpi/c/file_set_view.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved.
1414
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
1515
* reserved.
16-
* Copyright (c) 2015 Research Organization for Information Science
16+
* Copyright (c) 2015-2018 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
1818
* Copyright (c) 2017 IBM Corporation. All rights reserved.
1919
* $COPYRIGHT$
@@ -59,9 +59,9 @@ int MPI_File_set_view(MPI_File fh, MPI_Offset disp, MPI_Datatype etype,
5959
rc = MPI_ERR_FILE;
6060
fh = MPI_FILE_NULL;
6161
} else {
62-
OMPI_CHECK_DATATYPE_FOR_RECV(rc, etype, 0);
62+
OMPI_CHECK_DATATYPE_FOR_VIEW(rc, etype, 0);
6363
if (MPI_SUCCESS == rc) {
64-
OMPI_CHECK_DATATYPE_FOR_RECV(rc, filetype, 0);
64+
OMPI_CHECK_DATATYPE_FOR_VIEW(rc, filetype, 0);
6565
}
6666
}
6767
OMPI_ERRHANDLER_CHECK(rc, fh, rc, FUNC_NAME);

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)