25 #ifndef __USE_FILE_OFFSET64 26 #define __USE_FILE_OFFSET64 32 #include <sys/types.h> 50 int _sion_gen_info_from_gcomm_ompi(
int numFiles, MPI_Comm gComm,
int *filenumber,
int *lrank,
int *lsize)
53 int rc = SION_SUCCESS;
57 MPI_Comm_size(gComm, >asks);
58 MPI_Comm_rank(gComm, &gRank);
59 DPRINTFP((1,
"_sion_get_info_from_splitted_comm_mpi", gRank,
"enter: gcomm: %d of %d, numfiles=%d\n",
60 gRank,gtasks,numFiles));
62 if (gtasks < numFiles) {
63 return(_sion_errorprint_ompi(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
64 "_sion_gen_info_from_gcomm_mpi: Number of files(%d) cannot be bigger the the number of tasks(%d), aborting...\n",
68 task_per_file = gtasks / numFiles;
71 if (gRank >= (numFiles * task_per_file)) {
72 *filenumber = numFiles - 1;
75 *filenumber = gRank / task_per_file;
78 if(*filenumber == numFiles - 1) {
79 *lrank=gRank-(numFiles - 1)*task_per_file;
80 *lsize=gtasks-(numFiles - 1)*task_per_file;
82 *lrank=gRank%task_per_file;
86 DPRINTFP((1,
"_sion_get_info_from_splitted_comm_mpi", gRank,
"Global communicator divided in %d local communicators (%d: %d of %d)\n",
87 numFiles,*filenumber,*lrank,*lsize));
92 int _sion_get_info_from_splitted_comm_ompi(MPI_Comm gComm, MPI_Comm lComm,
int *numComm,
int *CommNumber,
int *lrank,
int *lsize) {
93 int gSize, gRank, lSize, lRank;
94 int *allRanks=NULL, *allSizes=NULL, i, ntasks;
96 int rc = SION_SUCCESS;
99 MPI_Comm_size(gComm, &gSize);
100 MPI_Comm_rank(gComm, &gRank);
102 if (lComm != MPI_COMM_NULL) {
103 MPI_Comm_size(lComm, &lSize);
104 MPI_Comm_rank(lComm, &lRank);
111 DPRINTFP((32,
"_sion_get_info_from_splitted_comm_mpi", gRank,
"lRank: %d\n", lRank));
115 allRanks = (
int *) malloc(gSize *
sizeof(
int));
116 allSizes = (
int *) malloc(gSize *
sizeof(
int));
117 if ((allRanks == NULL) || (allSizes == NULL)) {
118 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)));
123 MPI_Gather(&lRank, 1, MPI_INT, allRanks, 1, MPI_INT, 0, gComm);
124 MPI_Gather(&lSize, 1, MPI_INT, allSizes, 1, MPI_INT, 0, gComm);
129 for (i = 0; i < gSize; i++) {
130 if (allRanks[i] == 0) {
133 MPI_Send(&ncomms, 1, MPI_INT, i, i, gComm);
134 DPRINTFP((32,
"sion_paropen_comms_mpi", gRank,
"Sent ncomms=%05d to %d with TAG %d\n", ncomms, i, i));
141 ntasks += allSizes[i];
146 if ((lRank == 0) && (gRank != 0)) {
147 MPI_Recv(&color, 1, MPI_INT, 0, gRank, gComm, &status);
148 DPRINTFP((32,
"sion_paropen_comms_mpi", gRank,
"Received ncomms=%05d from %d with TAG %d\n", color, status.MPI_SOURCE, status.MPI_TAG));
152 MPI_Bcast(&ncomms, 1, MPI_INT, 0, gComm);
153 MPI_Bcast(&ntasks, 1, MPI_INT, 0, gComm);
156 DPRINTFP((32,
"_sion_get_info_from_splitted_comm_mpi", gRank,
"#Comms=%05d #Tasks=%05d #TotalTasks=%05d\n", ncomms, ntasks, gSize));
158 if (lComm != MPI_COMM_NULL) {
159 MPI_Bcast(&color, 1, MPI_INT, 0, lComm);
163 if(allRanks) free(allRanks);
164 if(allSizes) free(allSizes);
175 int _sion_errorprint_ompi(
int rc,
int level,
const char *format, ...)
183 int thread_num = omp_get_thread_num();
184 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
187 if (t) rankselect = atoi(t);
190 case _SION_ERROR_RETURN:
191 if((rankselect<0) || (rankselect==rank)) {
192 fprintf(stderr,
"SION_ERROR_RETURN on MPI rank %d, OMP thread %d, rc=%d: ",rank, thread_num,rc);
193 va_start(ap, format);
194 vfprintf(stderr, format, ap);
196 fprintf(stderr,
"\n");
200 case _SION_ERROR_ABORT:
201 if((rankselect<0) || (rankselect==rank)) {
202 fprintf(stderr,
"SION_ERROR_ABORT on MPI rank %d, OMP thread %d, rc=%d: ",rank, thread_num,rc);
203 va_start(ap, format);
204 vfprintf(stderr, format, ap);
206 fprintf(stderr,
"\n");
211 if((rankselect<0) || (rankselect==rank)) {
213 fprintf(stderr,
"SION_ERROR_UNKNOWN on MPI rank %d, OMP thread %d, rc=%d: ",rank, thread_num,rc);
214 va_start(ap, format);
215 vfprintf(stderr, format, ap);
217 fprintf(stderr,
"\n");
227 int _sion_map_rank_ompi_to_mpi(
int ompi_rank,
int num_threads) {
230 mpi_rank = (int) (ompi_rank / num_threads);
235 int _sion_map_rank_ompi_to_thread_num(
int ompi_rank,
int num_threads) {
238 thread_num = (int) (ompi_rank % num_threads);
244 int _sion_map_rank_mpi_to_ompi(
int mpi_rank,
int num_threads,
int thread_num) {
247 ompi_rank = mpi_rank * num_threads + thread_num;
252 int _sion_get_size_ompi(
int mpi_size,
int num_threads) {
255 ompi_size = mpi_size * num_threads;
char * _sion_getenv(const char *name)