1
1

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. open-mpi/ompi#4682

Signed-off-by: Gilles Gouaillardet <gilles@rist.or.jp>
Этот коммит содержится в:
Gilles Gouaillardet 2018-01-09 12:32:32 +09:00
родитель 1a17cb3b1c
Коммит 02f8215b25
5 изменённых файлов: 45 добавлений и 10 удалений

Просмотреть файл

@ -7,7 +7,7 @@
* Copyright (c) 2010-2017 Cisco Systems, Inc. All rights reserved * Copyright (c) 2010-2017 Cisco Systems, Inc. All rights reserved
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights * Copyright (c) 2013 Los Alamos National Security, LLC. All rights
* reserved. * reserved.
* Copyright (c) 2015-2017 Research Organization for Information Science * Copyright (c) 2015-2018 Research Organization for Information Science
* and Technology (RIST). All rights reserved. * and Technology (RIST). All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
@ -44,6 +44,8 @@ BEGIN_C_DECLS
/* These flags are on top of the flags in opal_datatype.h */ /* These flags are on top of the flags in opal_datatype.h */
/* Is the datatype predefined as MPI type (not necessarily as OPAL type, e.g. struct/block types) */ /* Is the datatype predefined as MPI type (not necessarily as OPAL type, e.g. struct/block types) */
#define OMPI_DATATYPE_FLAG_PREDEFINED 0x0200 #define OMPI_DATATYPE_FLAG_PREDEFINED 0x0200
#define OMPI_DATATYPE_FLAG_ANALYZED 0x0400
#define OMPI_DATATYPE_FLAG_MONOTONIC 0x0800
/* Keep trace of the type of the predefined datatypes */ /* Keep trace of the type of the predefined datatypes */
#define OMPI_DATATYPE_FLAG_DATA_INT 0x1000 #define OMPI_DATATYPE_FLAG_DATA_INT 0x1000
#define OMPI_DATATYPE_FLAG_DATA_FLOAT 0x2000 #define OMPI_DATATYPE_FLAG_DATA_FLOAT 0x2000
@ -152,13 +154,23 @@ ompi_datatype_is_contiguous_memory_layout( const ompi_datatype_t* type, int32_t
return opal_datatype_is_contiguous_memory_layout(&type->super, count); return opal_datatype_is_contiguous_memory_layout(&type->super, count);
} }
static inline int32_t
ompi_datatype_is_monotonic( ompi_datatype_t * type ) {
if (!(type->super.flags & OMPI_DATATYPE_FLAG_ANALYZED)) {
if (opal_datatype_is_monotonic(&type->super)) {
type->super.flags |= OMPI_DATATYPE_FLAG_MONOTONIC;
}
type->super.flags |= OMPI_DATATYPE_FLAG_ANALYZED;
}
return type->super.flags & OMPI_DATATYPE_FLAG_MONOTONIC;
}
static inline int32_t static inline int32_t
ompi_datatype_commit( ompi_datatype_t ** type ) ompi_datatype_commit( ompi_datatype_t ** type )
{ {
return opal_datatype_commit ( (opal_datatype_t*)*type ); return opal_datatype_commit ( (opal_datatype_t*)*type );
} }
OMPI_DECLSPEC int32_t ompi_datatype_destroy( ompi_datatype_t** type); OMPI_DECLSPEC int32_t ompi_datatype_destroy( ompi_datatype_t** type);

Просмотреть файл

@ -7,7 +7,7 @@
* Copyright (c) 2010-2012 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2010-2012 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights * Copyright (c) 2013 Los Alamos National Security, LLC. All rights
* reserved. * reserved.
* Copyright (c) 2015-2017 Research Organization for Information Science * Copyright (c) 2015-2018 Research Organization for Information Science
* and Technology (RIST). All rights reserved. * and Technology (RIST). All rights reserved.
* Copyright (c) 2016 FUJITSU LIMITED. All rights reserved. * Copyright (c) 2016 FUJITSU LIMITED. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
@ -416,6 +416,8 @@ extern const ompi_datatype_t* ompi_datatype_basicDatatypes[OMPI_DATATYPE_MPI_MAX
{ /*ompi_predefined_datatype_t*/ \ { /*ompi_predefined_datatype_t*/ \
{ /* ompi_datatype_t */ \ { /* ompi_datatype_t */ \
OMPI_DATATYPE_INITIALIZER_ ## TYPE (OMPI_DATATYPE_FLAG_PREDEFINED | \ OMPI_DATATYPE_INITIALIZER_ ## TYPE (OMPI_DATATYPE_FLAG_PREDEFINED | \
OMPI_DATATYPE_FLAG_ANALYZED | \
OMPI_DATATYPE_FLAG_MONOTONIC | \
(FLAGS)) /*super*/, \ (FLAGS)) /*super*/, \
OMPI_DATATYPE_EMPTY_DATA(NAME) /*id,d_f_to_c_index,d_keyhash,args,packed_description,name*/ \ OMPI_DATATYPE_EMPTY_DATA(NAME) /*id,d_f_to_c_index,d_keyhash,args,packed_description,name*/ \
}, \ }, \
@ -457,6 +459,8 @@ extern const ompi_datatype_t* ompi_datatype_basicDatatypes[OMPI_DATATYPE_MPI_MAX
.super = OPAL_OBJ_STATIC_INIT(opal_datatype_t), \ .super = OPAL_OBJ_STATIC_INIT(opal_datatype_t), \
.flags = OPAL_DATATYPE_FLAG_BASIC | \ .flags = OPAL_DATATYPE_FLAG_BASIC | \
OMPI_DATATYPE_FLAG_PREDEFINED | \ OMPI_DATATYPE_FLAG_PREDEFINED | \
OMPI_DATATYPE_FLAG_ANALYZED | \
OMPI_DATATYPE_FLAG_MONOTONIC | \
OMPI_DATATYPE_FLAG_DATA_FORTRAN | (FLAGS), \ OMPI_DATATYPE_FLAG_DATA_FORTRAN | (FLAGS), \
.id = OPAL_DATATYPE_ ## TYPE ## SIZE, \ .id = OPAL_DATATYPE_ ## TYPE ## SIZE, \
.bdt_used = (((uint32_t)1)<<(OPAL_DATATYPE_ ## TYPE ## SIZE)), \ .bdt_used = (((uint32_t)1)<<(OPAL_DATATYPE_ ## TYPE ## SIZE)), \

Просмотреть файл

@ -15,7 +15,7 @@
* Copyright (c) 2009 Oak Ridge National Labs. All rights reserved. * Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights * Copyright (c) 2013 Los Alamos National Security, LLC. All rights
* reserved. * reserved.
* Copyright (c) 2015-2017 Research Organization for Information Science * Copyright (c) 2015-2018 Research Organization for Information Science
* and Technology (RIST). All rights reserved. * and Technology (RIST). All rights reserved.
* Copyright (c) 2016 FUJITSU LIMITED. All rights reserved. * Copyright (c) 2016 FUJITSU LIMITED. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
@ -414,7 +414,9 @@ opal_pointer_array_t ompi_datatype_f_to_c_table = {{0}};
ompi_datatype_commit( &ptype ); \ ompi_datatype_commit( &ptype ); \
COPY_DATA_DESC( PDATA, ptype ); \ COPY_DATA_DESC( PDATA, ptype ); \
(PDATA)->super.flags &= ~OPAL_DATATYPE_FLAG_PREDEFINED; \ (PDATA)->super.flags &= ~OPAL_DATATYPE_FLAG_PREDEFINED; \
(PDATA)->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED; \ (PDATA)->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED | \
OMPI_DATATYPE_FLAG_ANALYZED | \
OMPI_DATATYPE_FLAG_MONOTONIC; \
ptype->super.desc.desc = NULL; \ ptype->super.desc.desc = NULL; \
ptype->super.opt_desc.desc = NULL; \ ptype->super.opt_desc.desc = NULL; \
OBJ_RELEASE( ptype ); \ OBJ_RELEASE( ptype ); \
@ -430,7 +432,9 @@ opal_pointer_array_t ompi_datatype_f_to_c_table = {{0}};
ompi_datatype_commit( &ptype ); \ ompi_datatype_commit( &ptype ); \
COPY_DATA_DESC( (PDATA), ptype ); \ COPY_DATA_DESC( (PDATA), ptype ); \
(PDATA)->super.flags &= ~OPAL_DATATYPE_FLAG_PREDEFINED; \ (PDATA)->super.flags &= ~OPAL_DATATYPE_FLAG_PREDEFINED; \
(PDATA)->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED; \ (PDATA)->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED | \
OMPI_DATATYPE_FLAG_ANALYZED | \
OMPI_DATATYPE_FLAG_MONOTONIC; \
ptype->super.desc.desc = NULL; \ ptype->super.desc.desc = NULL; \
ptype->super.opt_desc.desc = NULL; \ ptype->super.opt_desc.desc = NULL; \
OBJ_RELEASE( ptype ); \ OBJ_RELEASE( ptype ); \
@ -445,7 +449,9 @@ opal_pointer_array_t ompi_datatype_f_to_c_table = {{0}};
/* forget the language flag */ \ /* forget the language flag */ \
(PDATA)->super.flags &= ~OMPI_DATATYPE_FLAG_DATA_LANGUAGE; \ (PDATA)->super.flags &= ~OMPI_DATATYPE_FLAG_DATA_LANGUAGE; \
(PDATA)->super.flags &= ~OPAL_DATATYPE_FLAG_PREDEFINED; \ (PDATA)->super.flags &= ~OPAL_DATATYPE_FLAG_PREDEFINED; \
(PDATA)->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED; \ (PDATA)->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED | \
OMPI_DATATYPE_FLAG_ANALYZED | \
OMPI_DATATYPE_FLAG_MONOTONIC; \
} while(0) } while(0)

Просмотреть файл

@ -10,6 +10,8 @@
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2018 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -71,6 +73,17 @@ BEGIN_C_DECLS
else if( !opal_datatype_is_valid(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \ else if( !opal_datatype_is_valid(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
} while(0) } while(0)
#define OMPI_CHECK_DATATYPE_FOR_VIEW( RC, DDT, COUNT ) \
do { \
/* (RC) = MPI_SUCCESS; */ \
if( NULL == (DDT) || MPI_DATATYPE_NULL == (DDT) ) (RC) = MPI_ERR_TYPE; \
else if( (COUNT) < 0 ) (RC) = MPI_ERR_COUNT; \
else if( !opal_datatype_is_committed(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
/* XXX Fix flags else if( ompi_datatype_is_overlapped((DDT)) ) (RC) = MPI_ERR_TYPE; */ \
else if( !opal_datatype_is_valid(&((DDT)->super)) ) (RC) = MPI_ERR_TYPE; \
else if( !ompi_datatype_is_monotonic((DDT)) ) (RC) = MPI_ERR_TYPE; \
} while (0)
/* This macro has to be used to check the correctness of the user buffer depending on the datatype. /* This macro has to be used to check the correctness of the user buffer depending on the datatype.
* This macro expects that the DDT parameter is a valid pointer to an ompi datatype object. * This macro expects that the DDT parameter is a valid pointer to an ompi datatype object.

Просмотреть файл

@ -13,7 +13,7 @@
* Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved. * Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights * Copyright (c) 2013 Los Alamos National Security, LLC. All rights
* reserved. * reserved.
* Copyright (c) 2015 Research Organization for Information Science * Copyright (c) 2015-2018 Research Organization for Information Science
* and Technology (RIST). All rights reserved. * and Technology (RIST). All rights reserved.
* Copyright (c) 2017 IBM Corporation. All rights reserved. * Copyright (c) 2017 IBM Corporation. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
@ -59,9 +59,9 @@ int MPI_File_set_view(MPI_File fh, MPI_Offset disp, MPI_Datatype etype,
rc = MPI_ERR_FILE; rc = MPI_ERR_FILE;
fh = MPI_FILE_NULL; fh = MPI_FILE_NULL;
} else { } else {
OMPI_CHECK_DATATYPE_FOR_RECV(rc, etype, 0); OMPI_CHECK_DATATYPE_FOR_VIEW(rc, etype, 0);
if (MPI_SUCCESS == rc) { if (MPI_SUCCESS == rc) {
OMPI_CHECK_DATATYPE_FOR_RECV(rc, filetype, 0); OMPI_CHECK_DATATYPE_FOR_VIEW(rc, filetype, 0);
} }
} }
OMPI_ERRHANDLER_CHECK(rc, fh, rc, FUNC_NAME); OMPI_ERRHANDLER_CHECK(rc, fh, rc, FUNC_NAME);