From 39b007074264e7c40bcc7778d408602c6cacda6d Mon Sep 17 00:00:00 2001 From: George Bosilca Date: Thu, 17 Jun 2004 00:01:22 +0000 Subject: [PATCH] 100% compatible with f2c translation table. I create the table in the ddt_init and populate it with all fortran predefined datatypes. There are several datatypes that are not accesible from fortran, their f2c index is set to -1 actually. This commit was SVN r1340. --- src/datatype/datatype.h | 3 ++ src/datatype/dt_create.c | 5 ++ src/datatype/dt_module.c | 113 ++++++++++++++++++++++++++------------- 3 files changed, 83 insertions(+), 38 deletions(-) diff --git a/src/datatype/datatype.h b/src/datatype/datatype.h index 6292abb2ad..da0ea536bd 100644 --- a/src/datatype/datatype.h +++ b/src/datatype/datatype.h @@ -20,8 +20,11 @@ #include "errhandler/errhandler.h" #include "class/ompi_object.h" #include "class/ompi_hash_table.h" +#include "class/ompi_pointer_array.h" #include "mpi.h" +extern ompi_pointer_array_t *ompi_datatype_f_to_c_table; + /* if there are more basic datatypes than the number of bytes in the int type * the bdt_used field of the data description struct should be changed to long. */ diff --git a/src/datatype/dt_create.c b/src/datatype/dt_create.c index ad56acb53c..3e8ee042a6 100644 --- a/src/datatype/dt_create.c +++ b/src/datatype/dt_create.c @@ -26,6 +26,7 @@ static void __get_free_dt_struct( dt_desc_t* pData ) pData->true_ub = LONG_MIN; pData->lb = LONG_MAX; pData->ub = LONG_MIN; + pData->d_f_to_c_index = ompi_pointer_array_add(ompi_datatype_f_to_c_table, pData); } static void __destroy_ddt_struct( dt_desc_t* pData ) @@ -40,6 +41,10 @@ static void __destroy_ddt_struct( dt_desc_t* pData ) pData->opt_desc.used = 0; if( pData->args != NULL ) free( pData->args ); pData->args = NULL; + if( NULL != ompi_pointer_array_get_item(ompi_datatype_f_to_c_table, pData->d_f_to_c_index) ){ + ompi_pointer_array_set_item( ompi_datatype_f_to_c_table, pData->d_f_to_c_index, NULL ); + } + } OBJ_CLASS_INSTANCE(ompi_datatype_t, ompi_object_t, __get_free_dt_struct, __destroy_ddt_struct ); diff --git a/src/datatype/dt_module.c b/src/datatype/dt_module.c index f5c6282ec8..a0daaa9599 100644 --- a/src/datatype/dt_module.c +++ b/src/datatype/dt_module.c @@ -4,7 +4,7 @@ #include "datatype_internal.h" /* other fields starting after bdt_used (index of DT_LOOP should be ONE) */ -#define EMPTY_DATA(NAME) NULL, 0, "MPI_" # NAME, {0, 0, NULL}, {0, 0, NULL}, NULL, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } +#define EMPTY_DATA(NAME) NULL, -1, "MPI_" # NAME, {0, 0, NULL}, {0, 0, NULL}, NULL, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } #define BASEOBJ_DATA { OBJ_CLASS(ompi_datatype_t), 1 } #define INIT_BASIC_DATA( TYPE, ALIGN, NAME ) \ { BASEOBJ_DATA, sizeof(TYPE), 0, sizeof(TYPE), ALIGN, \ @@ -120,6 +120,8 @@ ompi_datatype_t* ompi_mpi_cxx_bool; ompi_datatype_t* ompi_mpi_2cplex = basicDatatypes + DT_2COMPLEX; ompi_datatype_t* ompi_mpi_2dblcplex = basicDatatypes + DT_2DOUBLE_COMPLEX; +ompi_pointer_array_t *ompi_datatype_f_to_c_table = NULL; + int local_sizes[DT_MAX_PREDEFINED]; /* VPS: fake convertor for time being / to provide pack/unpack functions */ @@ -195,49 +197,81 @@ static ompi_convertor_t* pDumpConv = NULL; int ompi_ddt_init( void ) { - int i; + int i; - for( i = 0; i < DT_MAX_PREDEFINED; i++ ) { - basicDatatypes[i].desc.desc = (dt_elem_desc_t*)malloc(sizeof(dt_elem_desc_t)); - basicDatatypes[i].desc.desc->flags = DT_FLAG_BASIC | DT_FLAG_CONTIGUOUS; - basicDatatypes[i].desc.desc->type = i; - basicDatatypes[i].desc.desc->count = 1; - basicDatatypes[i].desc.desc->disp = 0; - basicDatatypes[i].desc.desc->extent = basicDatatypes[i].size; - basicDatatypes[i].desc.length = 1; - basicDatatypes[i].desc.used = 1; - basicDatatypes[i].btypes[i] = 1; - } + for( i = 0; i < DT_MAX_PREDEFINED; i++ ) { + basicDatatypes[i].desc.desc = (dt_elem_desc_t*)malloc(sizeof(dt_elem_desc_t)); + basicDatatypes[i].desc.desc->flags = DT_FLAG_BASIC | DT_FLAG_CONTIGUOUS; + basicDatatypes[i].desc.desc->type = i; + basicDatatypes[i].desc.desc->count = 1; + basicDatatypes[i].desc.desc->disp = 0; + basicDatatypes[i].desc.desc->extent = basicDatatypes[i].size; + basicDatatypes[i].desc.length = 1; + basicDatatypes[i].desc.used = 1; + basicDatatypes[i].btypes[i] = 1; + } - /* the 2 complex datatypes (float and double) */ - DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_cplex, DT_COMPLEX_FLOAT, "MPI_COMPLEX", float, float, DT_FLOAT, DT_FLOAT ); - DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_dblcplex, DT_COMPLEX_DOUBLE, "MPI_DOUBLE_COMPLEX", double, double, DT_DOUBLE, DT_DOUBLE ); - /* C++ complex types */ - DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_cxx_cplex, DT_COMPLEX_FLOAT, "MPI_CXX_COMPLEX", float, float, DT_FLOAT, DT_FLOAT ); - DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_cxx_dblcplex, DT_COMPLEX_DOUBLE, "MPI_CXX_DOUBLE_COMPLEX", double, double, DT_DOUBLE, DT_DOUBLE ); - DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_cxx_ldblcplex, DT_COMPLEX_LONG_DOUBLE, "MPI_CXX_LONG_DOUBLE_COMPLEX", long double, long double, DT_LONG_DOUBLE, DT_LONG_DOUBLE ); + /* the 2 complex datatypes (float and double) */ + DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_cplex, DT_COMPLEX_FLOAT, "MPI_COMPLEX", float, float, DT_FLOAT, DT_FLOAT ); + DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_dblcplex, DT_COMPLEX_DOUBLE, "MPI_DOUBLE_COMPLEX", double, double, DT_DOUBLE, DT_DOUBLE ); + /* C++ complex types */ + DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_cxx_cplex, DT_COMPLEX_FLOAT, "MPI_CXX_COMPLEX", float, float, DT_FLOAT, DT_FLOAT ); + DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_cxx_dblcplex, DT_COMPLEX_DOUBLE, "MPI_CXX_DOUBLE_COMPLEX", double, double, DT_DOUBLE, DT_DOUBLE ); + DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_cxx_ldblcplex, DT_COMPLEX_LONG_DOUBLE, "MPI_CXX_LONG_DOUBLE_COMPLEX", long double, long double, DT_LONG_DOUBLE, DT_LONG_DOUBLE ); - /* Now the predefined MPI2 datatypes (they should last forever!) */ - DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_float_int, DT_FLOAT_INT, "MPI_FLOAT_INT", float, int, DT_FLOAT, DT_INT ); - DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_double_int, DT_DOUBLE_INT, "MPI_DOUBLE_INT", double, int, DT_DOUBLE, DT_INT ); - DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_long_int, DT_LONG_INT, "MPI_LONG_INT", long, int, DT_LONG, DT_INT ); - DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_short_int, DT_SHORT_INT, "MPI_SHORT_INT", short, int, DT_SHORT, DT_INT ); - DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_longdbl_int, DT_LONG_DOUBLE_INT, "MPI_LONG_DOUBLE_INT", long double, int, DT_LONG_DOUBLE, DT_INT ); + /* Now the predefined MPI2 datatypes (they should last forever!) */ + DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_float_int, DT_FLOAT_INT, "MPI_FLOAT_INT", float, int, DT_FLOAT, DT_INT ); + DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_double_int, DT_DOUBLE_INT, "MPI_DOUBLE_INT", double, int, DT_DOUBLE, DT_INT ); + DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_long_int, DT_LONG_INT, "MPI_LONG_INT", long, int, DT_LONG, DT_INT ); + DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_short_int, DT_SHORT_INT, "MPI_SHORT_INT", short, int, DT_SHORT, DT_INT ); + DECLARE_MPI2_COMPOSED_STRUCT_DDT( ompi_mpi_longdbl_int, DT_LONG_DOUBLE_INT, "MPI_LONG_DOUBLE_INT", long double, int, DT_LONG_DOUBLE, DT_INT ); - DECLARE_MPI2_COMPOSED_BLOCK_DDT( ompi_mpi_2int, DT_2INT, "MPI_2INT", DT_INT ); - DECLARE_MPI2_COMPOSED_BLOCK_DDT( ompi_mpi_2integer, DT_2INTEGER, "MPI_2INTEGER", DT_INT ); - DECLARE_MPI2_COMPOSED_BLOCK_DDT( ompi_mpi_2real, DT_2REAL, "MPI_2REAL", DT_FLOAT ); - DECLARE_MPI2_COMPOSED_BLOCK_DDT( ompi_mpi_2dblprec, DT_2DBLPREC, "MPI_2DOUBLE_PRECISION", DT_DOUBLE ); - DECLARE_MPI2_COMPOSED_BLOCK_DDT( ompi_mpi_2cplex, DT_2COMPLEX, "MPI_2COMPLEX", DT_COMPLEX_FLOAT ); - DECLARE_MPI2_COMPOSED_BLOCK_DDT( ompi_mpi_2dblcplex, DT_2DOUBLE_COMPLEX, "MPI_2DOUBLE_COMPLEX", DT_COMPLEX_DOUBLE ); + DECLARE_MPI2_COMPOSED_BLOCK_DDT( ompi_mpi_2int, DT_2INT, "MPI_2INT", DT_INT ); + DECLARE_MPI2_COMPOSED_BLOCK_DDT( ompi_mpi_2integer, DT_2INTEGER, "MPI_2INTEGER", DT_INT ); + DECLARE_MPI2_COMPOSED_BLOCK_DDT( ompi_mpi_2real, DT_2REAL, "MPI_2REAL", DT_FLOAT ); + DECLARE_MPI2_COMPOSED_BLOCK_DDT( ompi_mpi_2dblprec, DT_2DBLPREC, "MPI_2DOUBLE_PRECISION", DT_DOUBLE ); + DECLARE_MPI2_COMPOSED_BLOCK_DDT( ompi_mpi_2cplex, DT_2COMPLEX, "MPI_2COMPLEX", DT_COMPLEX_FLOAT ); + DECLARE_MPI2_COMPOSED_BLOCK_DDT( ompi_mpi_2dblcplex, DT_2DOUBLE_COMPLEX, "MPI_2DOUBLE_COMPLEX", DT_COMPLEX_DOUBLE ); - for( i = 0; i < DT_MAX_PREDEFINED; i++ ) - local_sizes[i] = basicDatatypes[i].size; + for( i = 0; i < DT_MAX_PREDEFINED; i++ ) + local_sizes[i] = basicDatatypes[i].size; - /* VPS: Create a fake convertor. No error checking here now, since - this will be removed sometime */ - ompi_convertor = ompi_convertor_create(0,0); - return OMPI_SUCCESS; + /* VPS: Create a fake convertor. No error checking here now, since + this will be removed sometime */ + ompi_convertor = ompi_convertor_create(0,0); + + /* Create the f2c translation table */ + ompi_datatype_f_to_c_table = OBJ_NEW(ompi_pointer_array_t); + if (NULL == ompi_datatype_f_to_c_table) { + return OMPI_ERROR; + } + + /* Start to populate the f2c index translation table */ + ompi_pointer_array_add( ompi_datatype_f_to_c_table, NULL ); /* why not ? */ + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_byte ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_packed ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_ub ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_lb ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_character ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_logic ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_integer ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_char ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_short ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_int ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_long_long ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_real ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_real ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_real ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_double ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_long_double ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_dblprec ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_cplex ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_dblcplex ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_2real ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_2dblcplex ); + ompi_pointer_array_add(ompi_datatype_f_to_c_table, ompi_mpi_2integer ); + + return OMPI_SUCCESS; } int ompi_ddt_finalize( void ) @@ -254,6 +288,9 @@ int ompi_ddt_finalize( void ) if( pDumpConv != NULL ) { OBJ_RELEASE( pDumpConv ); } + /* Get rid of the Fortran2C translation table */ + OBJ_RELEASE(ompi_datatype_f_to_c_table); + return OMPI_SUCCESS; }