Skip to content

Commit 872cf44

Browse files
authored
Improve the opal_pointer_array & more (#3369)
* Complete rewrite of opal_pointer_array Instead of a cache oblivious linear search use a bits array to speed up the management of the free space. As a result we slightly increase the memory used by the structure, but we get a significant boost in performance. Signed-off-by: George Bosilca <[email protected]> * Do not register datatypes in the f2c translation table. The registration is now done up into the Fortran layer, by forcing a call to MPI_Type_c2f. Signed-off-by: George Bosilca <[email protected]>
1 parent 23dad50 commit 872cf44

File tree

16 files changed

+260
-120
lines changed

16 files changed

+260
-120
lines changed

ompi/communicator/comm_init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ int ompi_comm_init(void)
8686

8787
/* Setup communicator array */
8888
OBJ_CONSTRUCT(&ompi_mpi_communicators, opal_pointer_array_t);
89-
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_mpi_communicators, 0,
89+
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_mpi_communicators, 16,
9090
OMPI_FORTRAN_HANDLE_MAX, 64) ) {
9191
return OMPI_ERROR;
9292
}
9393

9494
/* Setup f to c table (we can no longer use the cid as the fortran handle) */
9595
OBJ_CONSTRUCT(&ompi_comm_f_to_c_table, opal_pointer_array_t);
96-
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_comm_f_to_c_table, 0,
97-
OMPI_FORTRAN_HANDLE_MAX, 64) ) {
96+
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_comm_f_to_c_table, 8,
97+
OMPI_FORTRAN_HANDLE_MAX, 32) ) {
9898
return OMPI_ERROR;
9999
}
100100

ompi/datatype/ompi_datatype_create.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
static void __ompi_datatype_allocate( ompi_datatype_t* datatype )
3030
{
3131
datatype->args = NULL;
32-
datatype->d_f_to_c_index = opal_pointer_array_add(&ompi_datatype_f_to_c_table, datatype);
33-
/* Later generated datatypes will have their id according to the Fortran ID, as ALL types are registered */
34-
datatype->id = datatype->d_f_to_c_index;
32+
/* Do not add the newly created datatypes to the f2c translation table. We will add them only
33+
* if necessary, basically upon the first call the MPI_Datatype_f2c.
34+
*/
35+
datatype->d_f_to_c_index = -1;
36+
datatype->id = -1;
3537
datatype->d_keyhash = NULL;
3638
datatype->name[0] = '\0';
3739
datatype->packed_description = NULL;
@@ -48,8 +50,9 @@ static void __ompi_datatype_release(ompi_datatype_t * datatype)
4850
free( datatype->packed_description );
4951
datatype->packed_description = NULL;
5052
}
51-
if( NULL != opal_pointer_array_get_item(&ompi_datatype_f_to_c_table, datatype->d_f_to_c_index) ){
53+
if( datatype->d_f_to_c_index >= 0 ) {
5254
opal_pointer_array_set_item( &ompi_datatype_f_to_c_table, datatype->d_f_to_c_index, NULL );
55+
datatype->d_f_to_c_index = -1;
5356
}
5457
/* any pending attributes ? */
5558
if (NULL != datatype->d_keyhash) {

ompi/datatype/ompi_datatype_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ extern const ompi_datatype_t* ompi_datatype_basicDatatypes[OMPI_DATATYPE_MPI_MAX
403403

404404
#define OMPI_DATATYPE_EMPTY_DATA(NAME) \
405405
.id = OMPI_DATATYPE_MPI_ ## NAME, \
406-
.d_f_to_c_index = 0, \
406+
.d_f_to_c_index = -1, \
407407
.d_keyhash = NULL, \
408408
.args = NULL, \
409409
.packed_description = NULL, \

ompi/datatype/ompi_datatype_module.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2016 The University of Tennessee and The University
6+
* Copyright (c) 2004-2017 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
@@ -457,7 +457,7 @@ int32_t ompi_datatype_init( void )
457457
/* Create the f2c translation table */
458458
OBJ_CONSTRUCT(&ompi_datatype_f_to_c_table, opal_pointer_array_t);
459459
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_datatype_f_to_c_table,
460-
0, OMPI_FORTRAN_HANDLE_MAX, 64)) {
460+
64, OMPI_FORTRAN_HANDLE_MAX, 32)) {
461461
return OMPI_ERROR;
462462
}
463463
/* All temporary datatypes created on the following statement will get registered
@@ -512,7 +512,6 @@ int32_t ompi_datatype_init( void )
512512
/* Copy the desc pointer from the <OMPI_DATATYPE_MPI_MAX_PREDEFINED datatypes to
513513
the synonym types */
514514

515-
516515
/* Start to populate the f2c index translation table */
517516

518517
/* The order of the data registration should be the same as the
@@ -523,14 +522,14 @@ int32_t ompi_datatype_init( void )
523522
/* This macro makes everything significantly easier to read below.
524523
All hail the moog! :-) */
525524

526-
#define MOOG(name, index) \
527-
{ \
528-
ompi_mpi_##name.dt.d_f_to_c_index = \
529-
opal_pointer_array_add(&ompi_datatype_f_to_c_table, &ompi_mpi_##name); \
525+
#define MOOG(name, index) \
526+
do { \
527+
ompi_mpi_##name.dt.d_f_to_c_index = \
528+
opal_pointer_array_add(&ompi_datatype_f_to_c_table, &ompi_mpi_##name); \
530529
if( ompi_datatype_number_of_predefined_data < (ompi_mpi_##name).dt.d_f_to_c_index ) \
531530
ompi_datatype_number_of_predefined_data = (ompi_mpi_##name).dt.d_f_to_c_index; \
532-
assert( (index) == ompi_mpi_##name.dt.d_f_to_c_index ); \
533-
}
531+
assert( (index) == ompi_mpi_##name.dt.d_f_to_c_index ); \
532+
} while(0)
534533

535534
/*
536535
* This MUST match the order of ompi/include/mpif-values.pl

ompi/errhandler/errcode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2007 The University of Tennessee and The University
6+
* Copyright (c) 2004-2017 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -133,8 +133,8 @@ int ompi_mpi_errcode_init (void)
133133
/* Initialize the pointer array, which will hold the references to
134134
the error objects */
135135
OBJ_CONSTRUCT(&ompi_mpi_errcodes, opal_pointer_array_t);
136-
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_mpi_errcodes, 0,
137-
OMPI_FORTRAN_HANDLE_MAX, 64) ) {
136+
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_mpi_errcodes, 64,
137+
OMPI_FORTRAN_HANDLE_MAX, 32) ) {
138138
return OMPI_ERROR;
139139
}
140140

ompi/errhandler/errhandler.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2014 The University of Tennessee and The University
6+
* Copyright (c) 2004-2017 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -83,8 +83,8 @@ int ompi_errhandler_init(void)
8383
/* initialize ompi_errhandler_f_to_c_table */
8484

8585
OBJ_CONSTRUCT( &ompi_errhandler_f_to_c_table, opal_pointer_array_t);
86-
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_errhandler_f_to_c_table, 0,
87-
OMPI_FORTRAN_HANDLE_MAX, 64) ) {
86+
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_errhandler_f_to_c_table, 8,
87+
OMPI_FORTRAN_HANDLE_MAX, 16) ) {
8888
return OMPI_ERROR;
8989
}
9090

ompi/file/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2007 The University of Tennessee and The University
6+
* Copyright (c) 2004-2017 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -73,7 +73,7 @@ int ompi_file_init(void)
7373

7474
OBJ_CONSTRUCT(&ompi_file_f_to_c_table, opal_pointer_array_t);
7575
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_file_f_to_c_table, 0,
76-
OMPI_FORTRAN_HANDLE_MAX, 64) ) {
76+
OMPI_FORTRAN_HANDLE_MAX, 16) ) {
7777
return OMPI_ERROR;
7878
}
7979

ompi/group/group_init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2007 The University of Tennessee and The University
6+
* Copyright (c) 2004-2017 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -319,8 +319,8 @@ int ompi_group_init(void)
319319
{
320320
/* initialize ompi_group_f_to_c_table */
321321
OBJ_CONSTRUCT( &ompi_group_f_to_c_table, opal_pointer_array_t);
322-
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_group_f_to_c_table, 0,
323-
OMPI_FORTRAN_HANDLE_MAX, 64) ) {
322+
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_group_f_to_c_table, 4,
323+
OMPI_FORTRAN_HANDLE_MAX, 16) ) {
324324
return OMPI_ERROR;
325325
}
326326

ompi/info/info.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2007 The University of Tennessee and The University
6+
* Copyright (c) 2004-2017 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -102,7 +102,7 @@ int ompi_info_init(void)
102102

103103
OBJ_CONSTRUCT(&ompi_info_f_to_c_table, opal_pointer_array_t);
104104
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_info_f_to_c_table, 0,
105-
OMPI_FORTRAN_HANDLE_MAX, 64) ) {
105+
OMPI_FORTRAN_HANDLE_MAX, 16) ) {
106106
return OMPI_ERROR;
107107
}
108108

ompi/mpi/c/type_c2f.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
33
* University Research and Technology
44
* Corporation. All rights reserved.
5-
* Copyright (c) 2004-2005 The University of Tennessee and The University
5+
* Copyright (c) 2004-2017 The University of Tennessee and The University
66
* of Tennessee Research Foundation. All rights
77
* reserved.
88
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
@@ -55,5 +55,10 @@ MPI_Fint MPI_Type_c2f(MPI_Datatype datatype)
5555
}
5656
}
5757

58+
/* If necessary add the datatype to the f2c translation table */
59+
if( -1 == datatype->d_f_to_c_index ) {
60+
datatype->d_f_to_c_index = opal_pointer_array_add(&ompi_datatype_f_to_c_table, datatype);
61+
/* We don't check for error as returning a negative value is considered as an error */
62+
}
5863
return OMPI_INT_2_FINT(datatype->d_f_to_c_index);
5964
}

0 commit comments

Comments
 (0)