MED fichier
getBlocksOfEntitiesPartition.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2  *
3  * COPYRIGHT (C) 1999 - 2025 EDF R&D, CEA/DEN
4  * MED is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * MED is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with MED. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 #include <med.h>
20 #define MESGERR 1
21 #include "med_utils.h"
22 
23 
25 
26 
27 void getContinuousBlocksOfEntities(const int myrank, const int nproc, const med_int nentities,
28  med_size * const start, med_size * const stride, med_size * const count, med_size * blocksize,
29  int * const lastusedrank, med_size * const lastblocksize ) {
30 
31  int _nusedproc = nproc;
32  int _lastusedrank = 0;
33  med_size _blocksize = nentities/nproc;
34  /* _nblocks_pproc vaut 1 ou 0 si l'on utilise pas tous les processus */
35  int _nblocks_pproc = 0;
36 
37 
38  /*Tant que la taille des blocks est nulle on diminue le
39  nombre de processus utilisé jusqu'au minimum d'un processus
40  */
41  for (; (_blocksize < 1) && ( _nusedproc > 1 ) ; ) {
42  SSCRUTE("NOT USING ALL PROCESS");
43  --_nusedproc;
44  ISCRUTE(_nusedproc);
45  _blocksize = nentities/_nusedproc;
46  }
47  _lastusedrank = _nusedproc-1;
48 
49  if ( myrank < _nusedproc)
50  _nblocks_pproc = 1;
51  else
52  _blocksize = 0;
53 
54 /* if ( _blocksize == 0 ) { */
55 /* if (myrank == 0 ) { _nblocks_pproc=1;_blocksize=nentities;} */
56 /* _lastusedrank = 0; */
57 /* _nusedproc = 1; */
58 /* _blocksize = nentities; */ /*TODO : essayer de l'enlever maintenant : Ajouté pour symétrie des opération MPI_File, *count == 0*/
59 /* } else { */
60 /* _nblocks_pproc = 1; */
61 /* } */
62 
63  *start = myrank*_nblocks_pproc*_blocksize;
64  *stride = _blocksize;
65  *count = _nblocks_pproc;
66  *lastblocksize = 0;
67 
68  if ( myrank == _lastusedrank ) {
69  *blocksize = nentities+_blocksize*(1-_nusedproc);
70  } else {
71  *blocksize =_blocksize;
72  }
73  ++(*start);
74  *lastusedrank=_lastusedrank;
75  printf("My rank %d , start %lld , stride %lld , blocksize %lld , count %lld , lastblocksize %lld\n",
76  myrank,*start,*stride,*blocksize,*count,*lastblocksize);
77  return;
78 }
79 
80 void getCyclicBlocksOfEntities(const int myrank , const int nproc, const med_int nentities,
81  med_size * const start , med_size * const stride,
82  med_size * const io_count , med_size * blocksize,
83  int * const lastusedrank , med_size * const lastblocksize ) {
84 
85  /* int _nusedproc = nproc; */
86  int _lastusedrank = nproc-1;
87  int _nblocks_pproc = *io_count;
88  int _nblocks = _nblocks_pproc*nproc;
89  med_size _blocksize = 0;
90 
91  if (_nblocks) _blocksize=nentities/_nblocks;
92 
93  /*Tant que la taille des block est nulle on diminue le
94  nombre de blocks affecté par processus jusqu'au minimum
95  d'un block par processus
96  */
97  for (; (_blocksize < 1) && ( _nblocks_pproc > 1 ) ; ) {
98  --_nblocks_pproc;
99  _nblocks = _nblocks_pproc*nproc;
100  _blocksize = nentities/_nblocks;
101  }
102 
103 /* ISCRUTE(_nblocks_pproc); */
104 /* ISCRUTE(_blocksize); */
105 
106  /*Si la taille des blocks est toujours nulle,
107  c'est qu'il y a trop de processus pour le nombre d'entités :
108  -> On effectue alors une répartition par block contigüs qui prend
109  en compte la possible non affectation de certains processus.
110  */
111  if ( _blocksize == 0 ) {
112  MESSAGE("Downcasting getCyclicBlocksOfEntities to getContinuousBlocksOfEntities");
113  getContinuousBlocksOfEntities(myrank, nproc, nentities,
114  start, stride, io_count, blocksize, lastusedrank, lastblocksize );
115  return;
116  }
117 
118  /* A partir d'ici on est en mesure de calculer une répartition cyclique par block*/
119  *blocksize = _blocksize;
120  *stride = _blocksize*nproc;
121  *start = _blocksize*myrank;
122  *io_count = _nblocks_pproc;
123 
124  if (myrank == _lastusedrank) {
125  *lastblocksize = nentities + _blocksize*(1-nproc*_nblocks_pproc);
126  /*Dans le cas _nblocks_pproc==1 on a en fait une répartition contigüe des blocks
127  lastblocksize vaut alors 0 car il n'est pas utilisé.*/
128  if ( _nblocks_pproc == 1 ) {*blocksize=*lastblocksize;*lastblocksize=0;}
129  } else
130  *lastblocksize=0;
131 
132  ++(*start);
133  *lastusedrank=_lastusedrank;
134 /* printf("My rank %d, start %d, stride %d, blocksize %d, io_count %d, lastblocksize %d\n",myrank,*start,*stride,*blocksize,*io_count,*lastblocksize); */
135  return;
136 }
137 
138 
139 
140 
141 
142 
getContinuousBlocksOfEntities
void getContinuousBlocksOfEntities(const int myrank, const int nproc, const med_int nentities, med_size *const start, med_size *const stride, med_size *const count, med_size *blocksize, int *const lastusedrank, med_size *const lastblocksize)
Definition: getBlocksOfEntitiesPartition.c:27
med_int
int med_int
Definition: med.h:361
med_size
hsize_t med_size
Definition: med.h:348
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
ISCRUTE
#define ISCRUTE(entier)
Definition: med_utils.h:313
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:323
getCyclicBlocksOfEntities
void getCyclicBlocksOfEntities(const int myrank, const int nproc, const med_int nentities, med_size *const start, med_size *const stride, med_size *const io_count, med_size *blocksize, int *const lastusedrank, med_size *const lastblocksize)
Definition: getBlocksOfEntitiesPartition.c:80
med.h
med_utils.h
getBlocksOfEntitiesPartition.h