383 #ifndef OTF2_MPI_COLLECTIVES_H
384 #define OTF2_MPI_COLLECTIVES_H
406 MPI_Comm localComm );
422 uint32_t numberOfFiles );
434 MPI_Comm globalComm );
447 #ifdef OTF2_MPI_USE_PMPI
448 # define CALL_MPI( name ) P ## name
450 # define CALL_MPI( name ) name
451 # define OTF2_MPI_USE_PMPI
452 # define OTF2_MPI_USE_PMPI_undef_me
463 #ifndef OTF2_MPI_UINT8_T
464 # if MPI_VERSION >= 3
465 # define OTF2_MPI_UINT8_T MPI_UINT8_T
467 # define OTF2_MPI_UINT8_T MPI_UNSIGNED_CHAR
478 #ifndef OTF2_MPI_INT8_T
479 # if MPI_VERSION >= 3
480 # define OTF2_MPI_INT8_T MPI_INT8_T
482 # define OTF2_MPI_INT8_T MPI_CHAR
494 #ifndef OTF2_MPI_UINT16_T
495 # if MPI_VERSION >= 3
496 # define OTF2_MPI_UINT16_T MPI_UINT16_T
498 # define OTF2_MPI_UINT16_T MPI_UNSIGNED_SHORT
509 #ifndef OTF2_MPI_INT16_T
510 # if MPI_VERSION >= 3
511 # define OTF2_MPI_INT16_T MPI_INT16_T
513 # define OTF2_MPI_INT16_T MPI_SHORT
525 #ifndef OTF2_MPI_UINT32_T
526 # if MPI_VERSION >= 3
527 # define OTF2_MPI_UINT32_T MPI_UINT32_T
529 # define OTF2_MPI_UINT32_T MPI_UNSIGNED
540 #ifndef OTF2_MPI_INT32_T
541 # if MPI_VERSION >= 3
542 # define OTF2_MPI_INT32_T MPI_INT32_T
544 # define OTF2_MPI_INT32_T MPI_INT
556 #ifndef OTF2_MPI_UINT64_T
557 # define OTF2_MPI_UINT64_T MPI_UINT64_T
559 # error Please define OTF2_MPI_UINT64_T to a suitable MPI datatype for uint64_t.
570 #ifndef OTF2_MPI_INT64_T
571 # define OTF2_MPI_INT64_T MPI_INT64_T
573 # error Please define OTF2_MPI_INT64 to a suitable MPI datatype for int64_t.
584 #ifndef OTF2_MPI_FLOAT
585 # define OTF2_MPI_FLOAT MPI_FLOAT
595 #ifndef OTF2_MPI_DOUBLE
596 # define OTF2_MPI_DOUBLE MPI_DOUBLE
612 int displacements[ 1 ];
618 typedef struct OTF2_MPI_UserData
631 otf2_mpi_create_context( MPI_Comm comm,
641 uint32_t numberOfFiles );
650 OTF2_MPI_UserData* user_data = NULL;
660 if ( MPI_COMM_NULL == globalComm )
665 user_data = ( OTF2_MPI_UserData* )calloc( 1,
sizeof( *user_data ) );
671 otf2_mpi_get_collectives( &user_data->callbacks );
673 user_data->global = otf2_mpi_create_context( globalComm,
true );
674 if ( !user_data->global )
680 if ( MPI_COMM_NULL != localComm )
682 user_data->local = otf2_mpi_create_context( localComm,
true );
683 if ( !user_data->local )
691 &user_data->callbacks,
699 otf2_mpi_destroy_context( user_data->local );
700 otf2_mpi_destroy_context( user_data->global );
711 uint32_t numberOfFiles )
714 OTF2_MPI_UserData* user_data = NULL;
724 if ( MPI_COMM_NULL == globalComm )
729 user_data = ( OTF2_MPI_UserData* )calloc( 1,
sizeof( *user_data ) );
735 otf2_mpi_get_collectives( &user_data->callbacks );
737 user_data->global = otf2_mpi_create_context( globalComm,
true );
738 if ( !user_data->global )
744 user_data->local = otf2_mpi_split_context_by_number( user_data->global,
746 if ( !user_data->local )
753 &user_data->callbacks,
761 otf2_mpi_destroy_context( user_data->local );
762 otf2_mpi_destroy_context( user_data->global );
772 MPI_Comm globalComm )
775 OTF2_MPI_UserData* user_data = NULL;
785 if ( MPI_COMM_NULL == globalComm )
790 user_data = ( OTF2_MPI_UserData* )calloc( 1,
sizeof( *user_data ) );
796 otf2_mpi_get_collectives( &user_data->callbacks );
798 user_data->global = otf2_mpi_create_context( globalComm,
true );
799 if ( !user_data->global )
806 &user_data->callbacks,
814 otf2_mpi_destroy_context( user_data->global );
823 otf2_mpi_create_context( MPI_Comm comm,
829 ret = CALL_MPI( MPI_Comm_size ) ( comm, &size );
830 if ( MPI_SUCCESS != ret )
837 + ( ( size - 1 ) *
sizeof(
int ) ) );
843 new_context->size = size;
844 ret = CALL_MPI( MPI_Comm_rank ) ( comm, &new_context->rank );
845 if ( MPI_SUCCESS != ret )
853 ret = CALL_MPI( MPI_Comm_dup ) ( comm, &new_context->comm );
854 if ( MPI_SUCCESS != ret )
862 new_context->comm = comm;
872 if ( !collectiveContext )
877 CALL_MPI( MPI_Comm_free ) ( &collectiveContext->comm );
879 free( collectiveContext );
891 ret = CALL_MPI( MPI_Comm_split ) ( commContext->comm,
895 if ( MPI_SUCCESS != ret )
900 new_context = otf2_mpi_create_context( new_comm,
false );
903 CALL_MPI( MPI_Comm_free ) ( &new_comm );
913 uint32_t numberOfFiles )
916 int rem = commContext->size % numberOfFiles;
917 int local_size = commContext->size / numberOfFiles + !!rem;
921 for ( i = 0; i < commContext->rank; i++ )
924 if ( local_root + local_size == i + 1 )
926 local_root += local_size;
928 local_size -= file_number == rem;
933 return otf2_mpi_split_context( commContext,
942 #define case_return( TYPE, MPI_SUFFIX ) \
943 case OTF2_TYPE_ ## TYPE: \
944 return OTF2_MPI_ ## TYPE ## MPI_SUFFIX
947 case_return( UINT8, _T );
948 case_return( INT8, _T );
949 case_return( UINT16, _T );
950 case_return( INT16, _T );
951 case_return( UINT32, _T );
952 case_return( INT32, _T );
953 case_return( UINT64, _T );
954 case_return( INT64, _T );
955 case_return( FLOAT, );
956 case_return( DOUBLE, );
958 return MPI_DATATYPE_NULL;
965 otf2_mpi_collectives_release(
void* userData,
969 OTF2_MPI_UserData* user_data = ( OTF2_MPI_UserData* )userData;
971 ( void )globalCommContext;
972 ( void )localCommContext;
974 otf2_mpi_destroy_context( user_data->global );
975 otf2_mpi_destroy_context( user_data->local );
981 otf2_mpi_collectives_create_local_comm(
void* userData,
989 uint32_t numberOfFiles )
995 ( void )numberOfFiles;
997 *localCommContextOut = otf2_mpi_split_context( globalCommContext,
1001 return *localCommContextOut
1008 otf2_mpi_collectives_free_local_comm(
void* userData,
1013 otf2_mpi_destroy_context( localCommContext );
1020 otf2_mpi_collectives_get_size(
void* userData,
1026 *size = commContext->size;
1033 otf2_mpi_collectives_get_rank(
void* userData,
1039 *rank = commContext->rank;
1046 otf2_mpi_collectives_barrier(
void* userData,
1053 ret = CALL_MPI( MPI_Barrier ) ( commContext->comm );
1055 return MPI_SUCCESS == ret
1062 otf2_mpi_collectives_bcast(
void* userData,
1065 uint32_t numberElements,
1073 ret = CALL_MPI( MPI_Bcast ) ( data,
1075 otf2_mpi_get_type( type ),
1077 commContext->comm );
1079 return MPI_SUCCESS == ret
1086 otf2_mpi_collectives_gather(
void* userData,
1090 uint32_t numberElements,
1098 ret = CALL_MPI( MPI_Gather ) ( (
void* )inData,
1100 otf2_mpi_get_type( type ),
1103 otf2_mpi_get_type( type ),
1105 commContext->comm );
1107 return MPI_SUCCESS == ret
1114 otf2_mpi_collectives_gatherv(
void* userData,
1117 uint32_t inElements,
1119 const uint32_t* outElements,
1128 if ( (
int )root == commContext->rank )
1132 for ( i = 0; i < commContext->rank; ++i )
1134 commContext->displacements[ i ] = displ;
1135 displ += outElements[ i ];
1137 displs = commContext->displacements;
1140 ret = CALL_MPI( MPI_Gatherv ) ( (
void* )inData,
1142 otf2_mpi_get_type( type ),
1144 (
int* )outElements,
1146 otf2_mpi_get_type( type ),
1148 commContext->comm );
1150 return MPI_SUCCESS == ret
1157 otf2_mpi_collectives_scatter(
void* userData,
1161 uint32_t numberElements,
1167 int ret = CALL_MPI( MPI_Scatter ) ( (
void* )inData,
1169 otf2_mpi_get_type( type ),
1172 otf2_mpi_get_type( type ),
1174 commContext->comm );
1176 return MPI_SUCCESS == ret
1183 otf2_mpi_collectives_scatterv(
void* userData,
1186 const uint32_t* inElements,
1188 uint32_t outElements,
1196 if ( (
int )root == commContext->rank )
1200 for ( i = 0; i < commContext->rank; ++i )
1202 commContext->displacements[ i ] = displ;
1203 displ += inElements[ i ];
1205 displs = commContext->displacements;
1208 int ret = CALL_MPI( MPI_Scatterv ) ( (
void* )inData,
1211 otf2_mpi_get_type( type ),
1214 otf2_mpi_get_type( type ),
1216 commContext->comm );
1218 return MPI_SUCCESS == ret
1227 collectiveCallbacks->otf2_release = otf2_mpi_collectives_release;
1228 collectiveCallbacks->otf2_get_size = otf2_mpi_collectives_get_size;
1229 collectiveCallbacks->otf2_get_rank = otf2_mpi_collectives_get_rank;
1230 collectiveCallbacks->otf2_create_local_comm = otf2_mpi_collectives_create_local_comm;
1231 collectiveCallbacks->otf2_free_local_comm = otf2_mpi_collectives_free_local_comm;
1232 collectiveCallbacks->otf2_barrier = otf2_mpi_collectives_barrier;
1233 collectiveCallbacks->otf2_bcast = otf2_mpi_collectives_bcast;
1234 collectiveCallbacks->otf2_gather = otf2_mpi_collectives_gather;
1235 collectiveCallbacks->otf2_gatherv = otf2_mpi_collectives_gatherv;
1236 collectiveCallbacks->otf2_scatter = otf2_mpi_collectives_scatter;
1237 collectiveCallbacks->otf2_scatterv = otf2_mpi_collectives_scatterv;
1242 #ifdef OTF2_MPI_USE_PMPI_undef_me
1243 #undef OTF2_MPI_USE_PMPI
1244 #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:205
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