14 #define _XOPEN_SOURCE 700
27 #include <sys/types.h>
34 #include "sion_error_handler.h"
46 int _sion_gen_info_from_gcomm_ompi(
int numFiles, MPI_Comm gComm,
int *filenumber,
int *lrank,
int *lsize)
49 int rc = SION_SUCCESS;
53 MPI_Comm_size(gComm, >asks);
54 MPI_Comm_rank(gComm, &gRank);
55 DPRINTFP((1,
"_sion_get_info_from_splitted_comm_mpi", gRank,
"enter: gcomm: %d of %d, numfiles=%d\n",
56 gRank,gtasks,numFiles));
58 if (gtasks < numFiles) {
59 return(_sion_errorprint_ompi(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
60 "_sion_gen_info_from_gcomm_mpi: Number of files(%d) cannot be bigger the the number of tasks(%d), aborting...\n",
64 task_per_file = gtasks / numFiles;
67 if (gRank >= (numFiles * task_per_file)) {
68 *filenumber = numFiles - 1;
71 *filenumber = gRank / task_per_file;
74 if(*filenumber == numFiles - 1) {
75 *lrank=gRank-(numFiles - 1)*task_per_file;
76 *lsize=gtasks-(numFiles - 1)*task_per_file;
78 *lrank=gRank%task_per_file;
82 DPRINTFP((1,
"_sion_get_info_from_splitted_comm_mpi", gRank,
"Global communicator divided in %d local communicators (%d: %d of %d)\n",
83 numFiles,*filenumber,*lrank,*lsize));
88 int _sion_get_info_from_splitted_comm_ompi(MPI_Comm gComm, MPI_Comm lComm,
int *numComm,
int *CommNumber,
int *lrank,
int *lsize) {
89 int gSize, gRank, lSize, lRank;
90 int *allRanks=NULL, *allSizes=NULL, i, ntasks;
92 int rc = SION_SUCCESS;
95 MPI_Comm_size(gComm, &gSize);
96 MPI_Comm_rank(gComm, &gRank);
98 if (lComm != MPI_COMM_NULL) {
99 MPI_Comm_size(lComm, &lSize);
100 MPI_Comm_rank(lComm, &lRank);
107 DPRINTFP((32,
"_sion_get_info_from_splitted_comm_mpi", gRank,
"lRank: %d\n", lRank));
111 allRanks = (
int *) malloc(gSize *
sizeof(
int));
112 allSizes = (
int *) malloc(gSize *
sizeof(
int));
113 if ((allRanks == NULL) || (allSizes == NULL)) {
116 return(_sion_errorprint_ompi(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_get_info_from_splitted_comm_mpi: Cannot allocate temp arrays of size %lu\n", (
unsigned long) gSize *
sizeof(
int)));
121 MPI_Gather(&lRank, 1, MPI_INT, allRanks, 1, MPI_INT, 0, gComm);
122 MPI_Gather(&lSize, 1, MPI_INT, allSizes, 1, MPI_INT, 0, gComm);
127 for (i = 0; i < gSize; i++) {
128 if (allRanks[i] == 0) {
131 MPI_Send(&ncomms, 1, MPI_INT, i, i, gComm);
132 DPRINTFP((32,
"sion_paropen_comms_mpi", gRank,
"Sent ncomms=%05d to %d with TAG %d\n", ncomms, i, i));
139 ntasks += allSizes[i];
144 if ((lRank == 0) && (gRank != 0)) {
145 MPI_Recv(&color, 1, MPI_INT, 0, gRank, gComm, &status);
146 DPRINTFP((32,
"sion_paropen_comms_mpi", gRank,
"Received ncomms=%05d from %d with TAG %d\n", color, status.MPI_SOURCE, status.MPI_TAG));
150 MPI_Bcast(&ncomms, 1, MPI_INT, 0, gComm);
151 MPI_Bcast(&ntasks, 1, MPI_INT, 0, gComm);
154 DPRINTFP((32,
"_sion_get_info_from_splitted_comm_mpi", gRank,
"#Comms=%05d #Tasks=%05d #TotalTasks=%05d\n", ncomms, ntasks, gSize));
156 if (lComm != MPI_COMM_NULL) {
157 MPI_Bcast(&color, 1, MPI_INT, 0, lComm);
161 if(allRanks) free(allRanks);
162 if(allSizes) free(allSizes);
173 int _sion_errorprint_ompi(
int rc,
int level,
const char *format, ...)
178 int thread = omp_get_thread_num();
179 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
181 va_start(ap, format);
182 rc=__sion_errorprint_vargs(rc, level, rank, thread, format, ap);
191 int _sion_map_rank_ompi_to_mpi(
int ompi_rank,
int num_threads) {
194 mpi_rank = (int) (ompi_rank / num_threads);
199 int _sion_map_rank_ompi_to_thread_num(
int ompi_rank,
int num_threads) {
202 thread_num = (int) (ompi_rank % num_threads);
208 int _sion_map_rank_mpi_to_ompi(
int mpi_rank,
int num_threads,
int thread_num) {
211 ompi_rank = mpi_rank * num_threads + thread_num;
216 int _sion_get_size_ompi(
int mpi_size,
int num_threads) {
219 ompi_size = mpi_size * num_threads;