MED fichier
getBlocksOfEntitiesPartition.c
Aller à la documentation de ce fichier.
1/* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2020 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
27void getContinuousBlocksOfEntities(const int myrank, const int nproc, const 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 _blocksize = nentities/_nusedproc;
45 }
46 _lastusedrank = _nusedproc-1;
47
48 if ( myrank < _nusedproc)
49 _nblocks_pproc = 1;
50 else
51 _blocksize = 0;
52
53/* if ( _blocksize == 0 ) { */
54/* if (myrank == 0 ) { _nblocks_pproc=1;_blocksize=nentities;} */
55/* _lastusedrank = 0; */
56/* _nusedproc = 1; */
57/* _blocksize = nentities; */ /*TODO : essayer de l'enlever maintenant : Ajouté pour symétrie des opération MPI_File, *count == 0*/
58/* } else { */
59/* _nblocks_pproc = 1; */
60/* } */
61
62 *start = myrank*_nblocks_pproc*_blocksize;
63 *stride = _blocksize;
64 *count = _nblocks_pproc;
65 *lastblocksize = 0;
66
67 if ( myrank == _lastusedrank ) {
68 *blocksize = nentities+_blocksize*(1-_nusedproc);
69 } else {
70 *blocksize =_blocksize;
71 }
72 ++(*start);
73 *lastusedrank=_lastusedrank;
74 printf("My rank %d , start %l , stride %l , blocksize %l , count %l , lastblocksize %l\n",
75 myrank,*start,*stride,*blocksize,*count,*lastblocksize);
76 return;
77}
78
79void getCyclicBlocksOfEntities(const int myrank, const int nproc, const int nentities,
80 med_size * const start, med_size * const stride, med_size * const io_count, med_size * blocksize,
81 int * const lastusedrank, med_size * const lastblocksize ) {
82
83 int _nusedproc = nproc;
84 int _lastusedrank = nproc-1;
85 int _nblocks_pproc = *io_count;
86 int _nblocks = _nblocks_pproc*nproc;
87 med_size _blocksize = 0;
88
89 if (_nblocks) _blocksize=nentities/_nblocks;
90
91 /*Tant que la taille des block est nulle on diminue le
92 nombre de blocks affecté par processus jusqu'au minimum
93 d'un block par processus
94 */
95 for (; (_blocksize < 1) && ( _nblocks_pproc > 1 ) ; ) {
96 --_nblocks_pproc;
97 _nblocks = _nblocks_pproc*nproc;
98 _blocksize = nentities/_nblocks;
99 }
100
101/* ISCRUTE(_nblocks_pproc); */
102/* ISCRUTE(_blocksize); */
103
104 /*Si la taille des blocks est toujours nulle,
105 c'est qu'il y a trop de processus pour le nombre d'entités :
106 -> On effectue alors une répartition par block contigüs qui prend
107 en compte la possible non affectation de certains processus.
108 */
109 if ( _blocksize == 0 ) {
110 MESSAGE("Downcasting getCyclicBlocksOfEntities to getContinuousBlocksOfEntities");
111 getContinuousBlocksOfEntities(myrank, nproc, nentities,
112 start, stride, io_count, blocksize, lastusedrank, lastblocksize );
113 return;
114 }
115
116 /* A partir d'ici on est en mesure de calculer une répartition cyclique par block*/
117 *blocksize = _blocksize;
118 *stride = _blocksize*nproc;
119 *start = _blocksize*myrank;
120 *io_count = _nblocks_pproc;
121
122 if (myrank == _lastusedrank) {
123 *lastblocksize = nentities + _blocksize*(1-nproc*_nblocks_pproc);
124 /*Dans le cas _nblocks_pproc==1 on a en fait une répartition contigüe des blocks
125 lastblocksize vaut alors 0 car il n'est pas utilisé.*/
126 if ( _nblocks_pproc == 1 ) {*blocksize=*lastblocksize;*lastblocksize=0;}
127 } else
128 *lastblocksize=0;
129
130 ++(*start);
131 *lastusedrank=_lastusedrank;
132/* printf("My rank %d, start %d, stride %d, blocksize %d, io_count %d, lastblocksize %d\n",myrank,*start,*stride,*blocksize,*io_count,*lastblocksize); */
133 return;
134}
135
136
137
138
139
140
void getContinuousBlocksOfEntities(const int myrank, const int nproc, const int nentities, med_size *const start, med_size *const stride, med_size *const count, med_size *blocksize, int *const lastusedrank, med_size *const lastblocksize)
void getCyclicBlocksOfEntities(const int myrank, const int nproc, const 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)
hsize_t med_size
Definition: med.h:320
#define SSCRUTE(chaine)
Definition: med_utils.h:323
#define MESSAGE(chaine)
Definition: med_utils.h:324