Skip to content

Commit 02f8215

Browse files
committed
ompi: enhance MPI_File_set_view datatype check.
Per MPI 3.1 chapter 13.3 : "Derived etypes can be constructed by using any of the MPI datatype constructor routines, provided all resulting typemap displacements are non-negative and monotonically nondecreasing." Same restriction applies to ftypes. add the OMPI_DATATYPE_CHECK_FOR_VIEW() macro that is check the underlying opal_datatype_t is monotonic, on top of all checks performed in OMPI_DATATYPE_CHECK_FOR_RECV(). Since checking monotoniciy is expensive, check is only performed when needed, but the result is cached by ompi_datatype_is_monotonic(). Thanks Wei-keng Liao for the valuable feedback. Thanks George for the guidance. Refs. #4682 Signed-off-by: Gilles Gouaillardet <[email protected]>
1 parent 1a17cb3 commit 02f8215

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
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);

0 commit comments

Comments
 (0)