From 386a02d2ae4d73bb7e620ff4b0d56c5b0e469c65 Mon Sep 17 00:00:00 2001 From: George Bosilca Date: Sun, 11 Jun 2006 19:57:49 +0000 Subject: [PATCH] Rewrite the subarray strictly following the MPI standard. Set the lb and ub as it should be. I hope I get it right this time ... This commit was SVN r10293. --- ompi/mpi/c/type_create_subarray.c | 51 ++++++++++++++++++------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/ompi/mpi/c/type_create_subarray.c b/ompi/mpi/c/type_create_subarray.c index 47733ceab4..96cd939088 100644 --- a/ompi/mpi/c/type_create_subarray.c +++ b/ompi/mpi/c/type_create_subarray.c @@ -42,8 +42,8 @@ int MPI_Type_create_subarray(int ndims, { MPI_Datatype last_type; - int32_t i, step, end_loop; - int32_t block_length[2], start[2]; + int32_t i, step, start_loop, end_loop; + MPI_Aint size, displ, extent; if (MPI_PARAM_CHECK) { OMPI_ERR_INIT_FINALIZE(FUNC_NAME); @@ -67,41 +67,50 @@ int MPI_Type_create_subarray(int ndims, } } /* If the ndims is zero then return the NULL datatype */ - if( ndims < 1 ) { - *newtype = &ompi_mpi_datatype_null; + if( ndims < 2 ) { + if( 0 == ndims ) { + *newtype = &ompi_mpi_datatype_null; + return MPI_SUCCESS; + } + ompi_ddt_create_contiguous( subsize_array[0], oldtype, newtype ); return MPI_SUCCESS; } if( MPI_ORDER_C == order ) { - i = ndims - 1; + start_loop = i = ndims - 1; step = -1; end_loop = -1; } else { - i = 0; + start_loop = i = 0; step = 1; end_loop = ndims - 1; } + ompi_ddt_type_extent( oldtype, &extent ); + /* As we know that the ndims is at least 1 we can start by creating the first dimension data * outside the loop, such that we dont have to create a duplicate of the oldtype just to be able * to free it. */ - block_length[0] = subsize_array[i]; - block_length[1] = 0; - start[0] = start_array[i]; - start[1] = size_array[i]; - ompi_ddt_create_indexed( 2, block_length, start, oldtype, newtype ); - last_type = *newtype; - for( i += step; i != end_loop; i += step ) { - block_length[0] = subsize_array[i]; - block_length[1] = 0; - start[0] = start_array[i]; - start[1] = size_array[i]; - ompi_ddt_create_indexed( 2, block_length, start, last_type, newtype ); - ompi_ddt_destroy( &last_type ); - last_type = *newtype; - } + ompi_ddt_create_vector( subsize_array[i+step], subsize_array[i], size_array[i], + oldtype, newtype ); + last_type = *newtype; + size = size_array[i] * size_array[i+step]; + displ = start_array[i] + start_array[i+step] * size_array[i]; + for( i += 2 * step; i != end_loop; i += step ) { + last_type = *newtype; + ompi_ddt_create_vector( subsize_array[i], 1, size_array[i], + last_type, newtype ); + ompi_ddt_destroy( &last_type ); + displ += size * start_array[i]; + size *= size_array[i]; + } + + ompi_ddt_create_resized( last_type, displ * extent, + (size - start_array[start_loop]) * extent, newtype ); + ompi_ddt_destroy( &last_type ); + { int* a_i[5];