389 #ifndef OTF2_MPI_COLLECTIVES_H
390 #define OTF2_MPI_COLLECTIVES_H
412 MPI_Comm localComm );
428 uint32_t numberOfFiles );
440 MPI_Comm globalComm );
453 #ifdef OTF2_MPI_USE_PMPI
454 # define CALL_MPI( name ) P ## name
456 # define CALL_MPI( name ) name
457 # define OTF2_MPI_USE_PMPI
458 # define OTF2_MPI_USE_PMPI_undef_me
469 #ifndef OTF2_MPI_UINT8_T
470 # if MPI_VERSION >= 3
471 # define OTF2_MPI_UINT8_T MPI_UINT8_T
473 # define OTF2_MPI_UINT8_T MPI_UNSIGNED_CHAR
484 #ifndef OTF2_MPI_INT8_T
485 # if MPI_VERSION >= 3
486 # define OTF2_MPI_INT8_T MPI_INT8_T
488 # define OTF2_MPI_INT8_T MPI_CHAR
500 #ifndef OTF2_MPI_UINT16_T
501 # if MPI_VERSION >= 3
502 # define OTF2_MPI_UINT16_T MPI_UINT16_T
504 # define OTF2_MPI_UINT16_T MPI_UNSIGNED_SHORT
515 #ifndef OTF2_MPI_INT16_T
516 # if MPI_VERSION >= 3
517 # define OTF2_MPI_INT16_T MPI_INT16_T
519 # define OTF2_MPI_INT16_T MPI_SHORT
531 #ifndef OTF2_MPI_UINT32_T
532 # if MPI_VERSION >= 3
533 # define OTF2_MPI_UINT32_T MPI_UINT32_T
535 # define OTF2_MPI_UINT32_T MPI_UNSIGNED
546 #ifndef OTF2_MPI_INT32_T
547 # if MPI_VERSION >= 3
548 # define OTF2_MPI_INT32_T MPI_INT32_T
550 # define OTF2_MPI_INT32_T MPI_INT
562 #ifndef OTF2_MPI_UINT64_T
563 # define OTF2_MPI_UINT64_T MPI_UINT64_T
565 # error Please define OTF2_MPI_UINT64_T to a suitable MPI datatype for uint64_t.
576 #ifndef OTF2_MPI_INT64_T
577 # define OTF2_MPI_INT64_T MPI_INT64_T
579 # error Please define OTF2_MPI_INT64 to a suitable MPI datatype for int64_t.
590 #ifndef OTF2_MPI_FLOAT
591 # define OTF2_MPI_FLOAT MPI_FLOAT
601 #ifndef OTF2_MPI_DOUBLE
602 # define OTF2_MPI_DOUBLE MPI_DOUBLE
618 int displacements[ 1 ];
624 typedef struct OTF2_MPI_UserData
637 otf2_mpi_create_context( MPI_Comm comm,
647 uint32_t numberOfFiles );
656 OTF2_MPI_UserData* user_data = NULL;
666 if ( MPI_COMM_NULL == globalComm )
671 user_data = ( OTF2_MPI_UserData* )calloc( 1,
sizeof( *user_data ) );
677 otf2_mpi_get_collectives( &user_data->callbacks );
679 user_data->global = otf2_mpi_create_context( globalComm,
true );
680 if ( !user_data->global )
686 if ( MPI_COMM_NULL != localComm )
688 user_data->local = otf2_mpi_create_context( localComm,
true );
689 if ( !user_data->local )
697 &user_data->callbacks,
705 otf2_mpi_destroy_context( user_data->local );
706 otf2_mpi_destroy_context( user_data->global );
717 uint32_t numberOfFiles )
720 OTF2_MPI_UserData* user_data = NULL;
730 if ( MPI_COMM_NULL == globalComm )
735 user_data = ( OTF2_MPI_UserData* )calloc( 1,
sizeof( *user_data ) );
741 otf2_mpi_get_collectives( &user_data->callbacks );
743 user_data->global = otf2_mpi_create_context( globalComm,
true );
744 if ( !user_data->global )
750 user_data->local = otf2_mpi_split_context_by_number( user_data->global,
752 if ( !user_data->local )
759 &user_data->callbacks,
767 otf2_mpi_destroy_context( user_data->local );
768 otf2_mpi_destroy_context( user_data->global );
778 MPI_Comm globalComm )
781 OTF2_MPI_UserData* user_data = NULL;
791 if ( MPI_COMM_NULL == globalComm )
796 user_data = ( OTF2_MPI_UserData* )calloc( 1,
sizeof( *user_data ) );
802 otf2_mpi_get_collectives( &user_data->callbacks );
804 user_data->global = otf2_mpi_create_context( globalComm,
true );
805 if ( !user_data->global )
812 &user_data->callbacks,
820 otf2_mpi_destroy_context( user_data->global );
829 otf2_mpi_create_context( MPI_Comm comm,
835 ret = CALL_MPI( MPI_Comm_size ) ( comm, &size );
836 if ( MPI_SUCCESS != ret )
843 + ( ( size - 1 ) *
sizeof(
int ) ) );
849 new_context->size = size;
850 ret = CALL_MPI( MPI_Comm_rank ) ( comm, &new_context->rank );
851 if ( MPI_SUCCESS != ret )
859 ret = CALL_MPI( MPI_Comm_dup ) ( comm, &new_context->comm );
860 if ( MPI_SUCCESS != ret )
868 new_context->comm = comm;
878 if ( !collectiveContext )
883 CALL_MPI( MPI_Comm_free ) ( &collectiveContext->comm );
885 free( collectiveContext );
897 ret = CALL_MPI( MPI_Comm_split ) ( commContext->comm,
901 if ( MPI_SUCCESS != ret )
906 new_context = otf2_mpi_create_context( new_comm,
false );
909 CALL_MPI( MPI_Comm_free ) ( &new_comm );
919 uint32_t numberOfFiles )
922 int rem = commContext->size % numberOfFiles;
923 int local_size = commContext->size / numberOfFiles + !!rem;
927 for ( i = 0; i < commContext->rank; i++ )
930 if ( local_root + local_size == i + 1 )
932 local_root += local_size;
934 local_size -= file_number == rem;
939 return otf2_mpi_split_context( commContext,
948 #define case_return( TYPE, MPI_SUFFIX ) \
949 case OTF2_TYPE_ ## TYPE: \
950 return OTF2_MPI_ ## TYPE ## MPI_SUFFIX
953 case_return( UINT8, _T );
954 case_return( INT8, _T );
955 case_return( UINT16, _T );
956 case_return( INT16, _T );
957 case_return( UINT32, _T );
958 case_return( INT32, _T );
959 case_return( UINT64, _T );
960 case_return( INT64, _T );
961 case_return( FLOAT, );
962 case_return( DOUBLE, );
964 return MPI_DATATYPE_NULL;
971 otf2_mpi_collectives_release(
void* userData,
975 OTF2_MPI_UserData* user_data = ( OTF2_MPI_UserData* )userData;
977 ( void )globalCommContext;
978 ( void )localCommContext;
980 otf2_mpi_destroy_context( user_data->global );
981 otf2_mpi_destroy_context( user_data->local );
987 otf2_mpi_collectives_create_local_comm(
void* userData,
995 uint32_t numberOfFiles )
1001 ( void )numberOfFiles;
1003 *localCommContextOut = otf2_mpi_split_context( globalCommContext,
1007 return *localCommContextOut
1014 otf2_mpi_collectives_free_local_comm(
void* userData,
1019 otf2_mpi_destroy_context( localCommContext );
1026 otf2_mpi_collectives_get_size(
void* userData,
1032 *size = commContext->size;
1039 otf2_mpi_collectives_get_rank(
void* userData,
1045 *rank = commContext->rank;
1052 otf2_mpi_collectives_barrier(
void* userData,
1059 ret = CALL_MPI( MPI_Barrier ) ( commContext->comm );
1061 return MPI_SUCCESS == ret
1068 otf2_mpi_collectives_bcast(
void* userData,
1071 uint32_t numberElements,
1079 ret = CALL_MPI( MPI_Bcast ) ( data,
1081 otf2_mpi_get_type( type ),
1083 commContext->comm );
1085 return MPI_SUCCESS == ret
1092 otf2_mpi_collectives_gather(
void* userData,
1096 uint32_t numberElements,
1104 ret = CALL_MPI( MPI_Gather ) ( (
void* )inData,
1106 otf2_mpi_get_type( type ),
1109 otf2_mpi_get_type( type ),
1111 commContext->comm );
1113 return MPI_SUCCESS == ret
1120 otf2_mpi_collectives_gatherv(
void* userData,
1123 uint32_t inElements,
1125 const uint32_t* outElements,
1134 if ( (
int )root == commContext->rank )
1138 for ( i = 0; i < commContext->rank; ++i )
1140 commContext->displacements[ i ] = displ;
1141 displ += outElements[ i ];
1143 displs = commContext->displacements;
1146 ret = CALL_MPI( MPI_Gatherv ) ( (
void* )inData,
1148 otf2_mpi_get_type( type ),
1150 (
int* )outElements,
1152 otf2_mpi_get_type( type ),
1154 commContext->comm );
1156 return MPI_SUCCESS == ret
1163 otf2_mpi_collectives_scatter(
void* userData,
1167 uint32_t numberElements,
1173 int ret = CALL_MPI( MPI_Scatter ) ( (
void* )inData,
1175 otf2_mpi_get_type( type ),
1178 otf2_mpi_get_type( type ),
1180 commContext->comm );
1182 return MPI_SUCCESS == ret
1189 otf2_mpi_collectives_scatterv(
void* userData,
1192 const uint32_t* inElements,
1194 uint32_t outElements,
1202 if ( (
int )root == commContext->rank )
1206 for ( i = 0; i < commContext->rank; ++i )
1208 commContext->displacements[ i ] = displ;
1209 displ += inElements[ i ];
1211 displs = commContext->displacements;
1214 int ret = CALL_MPI( MPI_Scatterv ) ( (
void* )inData,
1217 otf2_mpi_get_type( type ),
1220 otf2_mpi_get_type( type ),
1222 commContext->comm );
1224 return MPI_SUCCESS == ret
1233 collectiveCallbacks->otf2_release = otf2_mpi_collectives_release;
1234 collectiveCallbacks->otf2_get_size = otf2_mpi_collectives_get_size;
1235 collectiveCallbacks->otf2_get_rank = otf2_mpi_collectives_get_rank;
1236 collectiveCallbacks->otf2_create_local_comm = otf2_mpi_collectives_create_local_comm;
1237 collectiveCallbacks->otf2_free_local_comm = otf2_mpi_collectives_free_local_comm;
1238 collectiveCallbacks->otf2_barrier = otf2_mpi_collectives_barrier;
1239 collectiveCallbacks->otf2_bcast = otf2_mpi_collectives_bcast;
1240 collectiveCallbacks->otf2_gather = otf2_mpi_collectives_gather;
1241 collectiveCallbacks->otf2_gatherv = otf2_mpi_collectives_gatherv;
1242 collectiveCallbacks->otf2_scatter = otf2_mpi_collectives_scatter;
1243 collectiveCallbacks->otf2_scatterv = otf2_mpi_collectives_scatterv;
1248 #ifdef OTF2_MPI_USE_PMPI_undef_me
1249 #undef OTF2_MPI_USE_PMPI
1250 #undef OTF2_MPI_USE_PMPI_undef_me
Record reading can continue.
Definition: OTF2_GeneralDefinitions.h:347
Main include file for applications using OTF2.
uint8_t OTF2_Type
Wrapper for enum OTF2_Type_enum.
Definition: OTF2_GeneralDefinitions.h:561
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:490
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:344
Signaling an error in the callback.
Definition: OTF2_GeneralDefinitions.h:358
struct OTF2_Archive_struct OTF2_Archive
Keeps all meta-data for an OTF2 archive.
Definition: OTF2_Archive.h:210
struct OTF2_Reader_struct OTF2_Reader
Keeps all necessary information for the reader.
Definition: OTF2_Reader.h:190
static OTF2_ErrorCode OTF2_MPI_Archive_SetCollectiveCallbacks(OTF2_Archive *archive, MPI_Comm globalComm, MPI_Comm localComm)
Register a MPI collective context to an OTF2 archive.
static OTF2_ErrorCode OTF2_MPI_Reader_SetCollectiveCallbacks(OTF2_Reader *reader, MPI_Comm globalComm)
Register a MPI collective context to an OTF2 reader.
static OTF2_ErrorCode OTF2_MPI_Archive_SetCollectiveCallbacksSplit(OTF2_Archive *archive, MPI_Comm globalComm, uint32_t numberOfFiles)
Register a MPI collective context to an OTF2 archive.
struct OTF2_CollectiveContext OTF2_CollectiveContext
User provided type for collective groups.
Definition: OTF2_Callbacks.h:303
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