getBlocksOfEntitiesPartition.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2012  EDF R&D, CEA/DEN
00004  *  MED is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 3 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  MED is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 
00019 #include <med.h>
00020 #define MESGERR 1
00021 #include "med_utils.h"
00022 
00023 
00024 #include "getBlocksOfEntitiesPartition.h"
00025 
00026 
00027 void getContinuousBlocksOfEntities(const int myrank, const int nproc, const int nbofentities,
00028                                     med_size * const start, med_size * const stride, med_size * const count, med_size * blocksize,
00029                                     int * const lastusedrank, med_size * const lastblocksize ) {
00030 
00031     int      _nusedproc      = nproc;
00032     int      _lastusedrank   = 0;
00033     med_size _blocksize      = nbofentities/nproc;
00034     /* _nblocks_pproc vaut 1 ou 0 si l'on utilise pas tous les processus */
00035     int      _nblocks_pproc  = 0;
00036 
00037 
00038     /*Tant que la taille des blocks est nulle on diminue le
00039       nombre de processus utilisé jusqu'au minimum d'un processus
00040     */
00041     for (; (_blocksize < 1) && ( _nusedproc > 1 ) ; ) {
00042       SSCRUTE("NOT USING ALL PROCESS");
00043       --_nusedproc;
00044       _blocksize = nbofentities/_nusedproc;
00045     }
00046     _lastusedrank   = _nusedproc-1;
00047 
00048     if ( myrank < _nusedproc)
00049       _nblocks_pproc = 1;
00050     else
00051       _blocksize = 0;
00052 
00053 /*     if ( _blocksize == 0 ) { */
00054 /*       if (myrank == 0 ) { _nblocks_pproc=1;_blocksize=nbofentities;} */
00055 /*       _lastusedrank = 0; */
00056 /*       _nusedproc = 1; */
00057 /*       _blocksize    = nbofentities; */ /*TODO : essayer de l'enlever maintenant : Ajouté pour symétrie des opération MPI_File, *count == 0*/
00058 /*     } else { */
00059 /*       _nblocks_pproc = 1; */
00060 /*     } */
00061 
00062     *start         = myrank*_nblocks_pproc*_blocksize;
00063     *stride        = _blocksize;
00064     *count         = _nblocks_pproc;
00065     *lastblocksize = 0;
00066 
00067     if ( myrank == _lastusedrank ) {
00068       *blocksize = nbofentities+_blocksize*(1-_nusedproc);
00069     } else {
00070       *blocksize =_blocksize;
00071     }
00072     ++(*start);
00073     *lastusedrank=_lastusedrank;
00074     printf("My rank %d, start %l, stride %l, blocksize %l, count %l, lastblocksize %l\n",myrank,*start,*stride,*blocksize,*count,*lastblocksize);
00075     return;
00076 }
00077 
00078 void getCyclicBlocksOfEntities(const int myrank, const int nproc, const int nbofentities,
00079                                  med_size * const start, med_size * const stride,  med_size * const io_count, med_size * blocksize,
00080                                  int * const lastusedrank, med_size * const lastblocksize ) {
00081 
00082     int      _nusedproc      = nproc;
00083     int      _lastusedrank   = nproc-1;
00084     int      _nblocks_pproc  = *io_count;
00085     int      _nblocks        = _nblocks_pproc*nproc;
00086     med_size _blocksize      = 0;
00087 
00088     if (_nblocks) _blocksize=nbofentities/_nblocks;
00089 
00090     /*Tant que la taille des block est nulle on diminue le
00091      nombre de blocks affecté par processus jusqu'au minimum
00092      d'un block par processus
00093     */
00094     for (; (_blocksize < 1) && ( _nblocks_pproc > 1 ) ; ) {
00095       --_nblocks_pproc;
00096       _nblocks   = _nblocks_pproc*nproc;
00097       _blocksize = nbofentities/_nblocks;
00098     }
00099 
00100 /*     ISCRUTE(_nblocks_pproc); */
00101 /*     ISCRUTE(_blocksize); */
00102 
00103     /*Si la taille des blocks est toujours nulle,
00104       c'est qu'il y a trop de processus pour le nombre d'entités :
00105       -> On effectue alors une répartition par block contigüs qui prend
00106       en compte la possible non affectation de certains processus.
00107     */
00108     if ( _blocksize == 0 ) {
00109       MESSAGE("Downcasting getCyclicBlocksOfEntities to getContinuousBlocksOfEntities");
00110       getContinuousBlocksOfEntities(myrank, nproc, nbofentities,
00111                                     start, stride, io_count, blocksize, lastusedrank, lastblocksize );
00112       return;
00113     }
00114 
00115     /* A partir d'ici on est en mesure de calculer une répartition cyclique par block*/
00116     *blocksize     = _blocksize;
00117     *stride        = _blocksize*nproc;
00118     *start         = _blocksize*myrank;
00119     *io_count      = _nblocks_pproc;
00120 
00121     if (myrank == _lastusedrank) {
00122       *lastblocksize = nbofentities + _blocksize*(1-nproc*_nblocks_pproc);
00123       /*Dans le cas _nblocks_pproc==1 on a en fait une répartition contigüe des blocks
00124        lastblocksize vaut alors 0 car il n'est pas utilisé.*/
00125       if ( _nblocks_pproc == 1 ) {*blocksize=*lastblocksize;*lastblocksize=0;}
00126     } else
00127       *lastblocksize=0;
00128 
00129     ++(*start);
00130     *lastusedrank=_lastusedrank;
00131 /*     printf("My rank %d, start %d, stride %d, blocksize %d, io_count %d, lastblocksize %d\n",myrank,*start,*stride,*blocksize,*io_count,*lastblocksize); */
00132     return;
00133 }
00134 
00135 
00136 
00137 
00138 
00139 

Généré le Mon Apr 23 11:30:25 2012 pour MED fichier par  doxygen 1.6.1