389 #ifndef OTF2_MPI_COLLECTIVES_H
390 #define OTF2_MPI_COLLECTIVES_H
414 MPI_Comm localComm );
430 uint32_t numberOfFiles );
442 MPI_Comm globalComm );
455 #ifdef OTF2_MPI_USE_PMPI
456 # define CALL_MPI( name ) P ## name
458 # define CALL_MPI( name ) name
459 # define OTF2_MPI_USE_PMPI
460 # define OTF2_MPI_USE_PMPI_undef_me
471 #ifndef OTF2_MPI_UINT8_T
472 # if MPI_VERSION >= 3
473 # define OTF2_MPI_UINT8_T MPI_UINT8_T
475 # define OTF2_MPI_UINT8_T MPI_UNSIGNED_CHAR
486 #ifndef OTF2_MPI_INT8_T
487 # if MPI_VERSION >= 3
488 # define OTF2_MPI_INT8_T MPI_INT8_T
490 # define OTF2_MPI_INT8_T MPI_CHAR
502 #ifndef OTF2_MPI_UINT16_T
503 # if MPI_VERSION >= 3
504 # define OTF2_MPI_UINT16_T MPI_UINT16_T
506 # define OTF2_MPI_UINT16_T MPI_UNSIGNED_SHORT
517 #ifndef OTF2_MPI_INT16_T
518 # if MPI_VERSION >= 3
519 # define OTF2_MPI_INT16_T MPI_INT16_T
521 # define OTF2_MPI_INT16_T MPI_SHORT
533 #ifndef OTF2_MPI_UINT32_T
534 # if MPI_VERSION >= 3
535 # define OTF2_MPI_UINT32_T MPI_UINT32_T
537 # define OTF2_MPI_UINT32_T MPI_UNSIGNED
548 #ifndef OTF2_MPI_INT32_T
549 # if MPI_VERSION >= 3
550 # define OTF2_MPI_INT32_T MPI_INT32_T
552 # define OTF2_MPI_INT32_T MPI_INT
564 #ifndef OTF2_MPI_UINT64_T
565 # define OTF2_MPI_UINT64_T MPI_UINT64_T
567 # error Please define OTF2_MPI_UINT64_T to a suitable MPI datatype for uint64_t.
578 #ifndef OTF2_MPI_INT64_T
579 # define OTF2_MPI_INT64_T MPI_INT64_T
581 # error Please define OTF2_MPI_INT64 to a suitable MPI datatype for int64_t.
592 #ifndef OTF2_MPI_FLOAT
593 # define OTF2_MPI_FLOAT MPI_FLOAT
603 #ifndef OTF2_MPI_DOUBLE
604 # define OTF2_MPI_DOUBLE MPI_DOUBLE
620 int displacements[ 1 ];
626 typedef struct OTF2_MPI_UserData
639 otf2_mpi_create_context( MPI_Comm comm,
649 uint32_t numberOfFiles );
658 OTF2_MPI_UserData* user_data = NULL;
668 if ( MPI_COMM_NULL == globalComm )
673 user_data = ( OTF2_MPI_UserData* )calloc( 1,
sizeof( *user_data ) );
679 otf2_mpi_get_collectives( &user_data->callbacks );
681 user_data->global = otf2_mpi_create_context( globalComm,
true );
682 if ( !user_data->global )
688 if ( MPI_COMM_NULL != localComm )
690 user_data->local = otf2_mpi_create_context( localComm,
true );
691 if ( !user_data->local )
699 &user_data->callbacks,
707 otf2_mpi_destroy_context( user_data->local );
708 otf2_mpi_destroy_context( user_data->global );
719 uint32_t numberOfFiles )
722 OTF2_MPI_UserData* user_data = NULL;
732 if ( MPI_COMM_NULL == globalComm )
737 user_data = ( OTF2_MPI_UserData* )calloc( 1,
sizeof( *user_data ) );
743 otf2_mpi_get_collectives( &user_data->callbacks );
745 user_data->global = otf2_mpi_create_context( globalComm,
true );
746 if ( !user_data->global )
752 user_data->local = otf2_mpi_split_context_by_number( user_data->global,
754 if ( !user_data->local )
761 &user_data->callbacks,
769 otf2_mpi_destroy_context( user_data->local );
770 otf2_mpi_destroy_context( user_data->global );
780 MPI_Comm globalComm )
783 OTF2_MPI_UserData* user_data = NULL;
793 if ( MPI_COMM_NULL == globalComm )
798 user_data = ( OTF2_MPI_UserData* )calloc( 1,
sizeof( *user_data ) );
804 otf2_mpi_get_collectives( &user_data->callbacks );
806 user_data->global = otf2_mpi_create_context( globalComm,
true );
807 if ( !user_data->global )
814 &user_data->callbacks,
822 otf2_mpi_destroy_context( user_data->global );
831 otf2_mpi_create_context( MPI_Comm comm,
837 ret = CALL_MPI( MPI_Comm_size ) ( comm, &size );
838 if ( MPI_SUCCESS != ret )
845 + ( ( size - 1 ) *
sizeof(
int ) ) );
851 new_context->size = size;
852 ret = CALL_MPI( MPI_Comm_rank ) ( comm, &new_context->rank );
853 if ( MPI_SUCCESS != ret )
861 ret = CALL_MPI( MPI_Comm_dup ) ( comm, &new_context->comm );
862 if ( MPI_SUCCESS != ret )
870 new_context->comm = comm;
880 if ( !collectiveContext )
885 CALL_MPI( MPI_Comm_free ) ( &collectiveContext->comm );
887 free( collectiveContext );
899 ret = CALL_MPI( MPI_Comm_split ) ( commContext->comm,
903 if ( MPI_SUCCESS != ret )
908 new_context = otf2_mpi_create_context( new_comm,
false );
911 CALL_MPI( MPI_Comm_free ) ( &new_comm );
921 uint32_t numberOfFiles )
924 int rem = commContext->size % numberOfFiles;
925 int local_size = commContext->size / numberOfFiles + !!rem;
929 for ( i = 0; i < commContext->rank; i++ )
932 if ( local_root + local_size == i + 1 )
934 local_root += local_size;
936 local_size -= file_number == rem;
941 return otf2_mpi_split_context( commContext,
950 #define case_return( TYPE, MPI_SUFFIX ) \
951 case OTF2_TYPE_ ## TYPE: \
952 return OTF2_MPI_ ## TYPE ## MPI_SUFFIX
955 case_return( UINT8, _T );
956 case_return( INT8, _T );
957 case_return( UINT16, _T );
958 case_return( INT16, _T );
959 case_return( UINT32, _T );
960 case_return( INT32, _T );
961 case_return( UINT64, _T );
962 case_return( INT64, _T );
963 case_return( FLOAT, );
964 case_return( DOUBLE, );
966 return MPI_DATATYPE_NULL;
973 otf2_mpi_collectives_release(
void* userData,
977 OTF2_MPI_UserData* user_data = ( OTF2_MPI_UserData* )userData;
979 ( void )globalCommContext;
980 ( void )localCommContext;
982 otf2_mpi_destroy_context( user_data->global );
983 otf2_mpi_destroy_context( user_data->local );
989 otf2_mpi_collectives_create_local_comm(
void* userData,
997 uint32_t numberOfFiles )
1003 ( void )numberOfFiles;
1005 *localCommContextOut = otf2_mpi_split_context( globalCommContext,
1009 return *localCommContextOut
1016 otf2_mpi_collectives_free_local_comm(
void* userData,
1021 otf2_mpi_destroy_context( localCommContext );
1028 otf2_mpi_collectives_get_size(
void* userData,
1034 *size = commContext->size;
1041 otf2_mpi_collectives_get_rank(
void* userData,
1047 *rank = commContext->rank;
1054 otf2_mpi_collectives_barrier(
void* userData,
1061 ret = CALL_MPI( MPI_Barrier ) ( commContext->comm );
1063 return MPI_SUCCESS == ret
1070 otf2_mpi_collectives_bcast(
void* userData,
1073 uint32_t numberElements,
1081 ret = CALL_MPI( MPI_Bcast ) ( data,
1083 otf2_mpi_get_type( type ),
1085 commContext->comm );
1087 return MPI_SUCCESS == ret
1094 otf2_mpi_collectives_gather(
void* userData,
1098 uint32_t numberElements,
1106 ret = CALL_MPI( MPI_Gather ) ( (
void* )inData,
1108 otf2_mpi_get_type( type ),
1111 otf2_mpi_get_type( type ),
1113 commContext->comm );
1115 return MPI_SUCCESS == ret
1122 otf2_mpi_collectives_gatherv(
void* userData,
1125 uint32_t inElements,
1127 const uint32_t* outElements,
1136 if ( (
int )root == commContext->rank )
1140 for ( i = 0; i < commContext->rank; ++i )
1142 commContext->displacements[ i ] = displ;
1143 displ += outElements[ i ];
1145 displs = commContext->displacements;
1148 ret = CALL_MPI( MPI_Gatherv ) ( (
void* )inData,
1150 otf2_mpi_get_type( type ),
1152 (
int* )outElements,
1154 otf2_mpi_get_type( type ),
1156 commContext->comm );
1158 return MPI_SUCCESS == ret
1165 otf2_mpi_collectives_scatter(
void* userData,
1169 uint32_t numberElements,
1175 int ret = CALL_MPI( MPI_Scatter ) ( (
void* )inData,
1177 otf2_mpi_get_type( type ),
1180 otf2_mpi_get_type( type ),
1182 commContext->comm );
1184 return MPI_SUCCESS == ret
1191 otf2_mpi_collectives_scatterv(
void* userData,
1194 const uint32_t* inElements,
1196 uint32_t outElements,
1204 if ( (
int )root == commContext->rank )
1208 for ( i = 0; i < commContext->rank; ++i )
1210 commContext->displacements[ i ] = displ;
1211 displ += inElements[ i ];
1213 displs = commContext->displacements;
1216 int ret = CALL_MPI( MPI_Scatterv ) ( (
void* )inData,
1219 otf2_mpi_get_type( type ),
1222 otf2_mpi_get_type( type ),
1224 commContext->comm );
1226 return MPI_SUCCESS == ret
1235 collectiveCallbacks->otf2_release = otf2_mpi_collectives_release;
1236 collectiveCallbacks->otf2_get_size = otf2_mpi_collectives_get_size;
1237 collectiveCallbacks->otf2_get_rank = otf2_mpi_collectives_get_rank;
1238 collectiveCallbacks->otf2_create_local_comm = otf2_mpi_collectives_create_local_comm;
1239 collectiveCallbacks->otf2_free_local_comm = otf2_mpi_collectives_free_local_comm;
1240 collectiveCallbacks->otf2_barrier = otf2_mpi_collectives_barrier;
1241 collectiveCallbacks->otf2_bcast = otf2_mpi_collectives_bcast;
1242 collectiveCallbacks->otf2_gather = otf2_mpi_collectives_gather;
1243 collectiveCallbacks->otf2_gatherv = otf2_mpi_collectives_gatherv;
1244 collectiveCallbacks->otf2_scatter = otf2_mpi_collectives_scatter;
1245 collectiveCallbacks->otf2_scatterv = otf2_mpi_collectives_scatterv;
1250 #ifdef OTF2_MPI_USE_PMPI_undef_me
1251 #undef OTF2_MPI_USE_PMPI
1252 #undef OTF2_MPI_USE_PMPI_undef_me
Record reading can continue.
Definition: OTF2_GeneralDefinitions.h:352
Main include file for applications using OTF2.
uint8_t OTF2_Type
Wrapper for enum OTF2_Type_enum.
Definition: OTF2_GeneralDefinitions.h:596
Definition: OTF2_ErrorCodes.h:66
Definition: OTF2_ErrorCodes.h:231
Definition: OTF2_ErrorCodes.h:245
Struct which holds all collective callbacks.
Definition: OTF2_Callbacks.h:497
OTF2_ErrorCode OTF2_Reader_SetCollectiveCallbacks(OTF2_Reader *reader, const OTF2_CollectiveCallbacks *collectiveCallbacks, void *collectiveData, OTF2_CollectiveContext *globalCommContext, OTF2_CollectiveContext *localCommContext)
Set the collective callbacks for the reader.
OTF2_ErrorCode
Definition: OTF2_ErrorCodes.h:54
OTF2_CallbackCode
Return value to indicate that the record reading should be interrupted.
Definition: OTF2_GeneralDefinitions.h:349
Signaling an error in the callback.
Definition: OTF2_GeneralDefinitions.h:363
struct OTF2_Archive_struct OTF2_Archive
Keeps all meta-data for an OTF2 archive.
Definition: OTF2_Archive.h:220
struct OTF2_Reader_struct OTF2_Reader
Keeps all necessary information for the reader.
Definition: OTF2_Reader.h:193
static OTF2_ErrorCode OTF2_MPI_Archive_SetCollectiveCallbacks(OTF2_Archive *archive, MPI_Comm globalComm, MPI_Comm localComm)
Register an MPI collective context to an OTF2 archive.
static OTF2_ErrorCode OTF2_MPI_Reader_SetCollectiveCallbacks(OTF2_Reader *reader, MPI_Comm globalComm)
Register an MPI collective context to an OTF2 reader.
static OTF2_ErrorCode OTF2_MPI_Archive_SetCollectiveCallbacksSplit(OTF2_Archive *archive, MPI_Comm globalComm, uint32_t numberOfFiles)
Register an MPI collective context to an OTF2 archive.
struct OTF2_CollectiveContext OTF2_CollectiveContext
User provided type for collective groups.
Definition: OTF2_Callbacks.h:310
OTF2_ErrorCode OTF2_Archive_SetCollectiveCallbacks(OTF2_Archive *archive, const OTF2_CollectiveCallbacks *collectiveCallbacks, void *collectiveData, OTF2_CollectiveContext *globalCommContext, OTF2_CollectiveContext *localCommContext)
Set the collective callbacks for the archive.
Definition: OTF2_ErrorCodes.h:247