getBlocksOfEntitiesPartition.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2011  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   = nproc-1;
00033     med_size _blocksize      = nbofentities/nproc;
00034     int      _nblocks_pproc  = 0;
00035 
00036     /*TODO : Améliorer cette gestion pour affecter plus de processus */
00037     if ( _blocksize == 0 ) {
00038       if (myrank == 0 ) { _nblocks_pproc=1;_blocksize=nbofentities;}
00039       _lastusedrank = 0;
00040       _nusedproc = 1;
00041       _blocksize    = nbofentities; /*TODO : essayer de l'enlever maintenant*/ /*Ajouter pour symétrie des opération MPI_File, *count == 0*/
00042     } else {
00043       _nblocks_pproc = 1;
00044     }
00045 
00046     *start         = myrank*_nblocks_pproc*_blocksize;
00047     *stride        = _blocksize;
00048     *count         = _nblocks_pproc;
00049     *lastblocksize = 0;
00050 
00051     if ( myrank == _lastusedrank ) {
00052       *blocksize = nbofentities+_blocksize*(1-_nusedproc);
00053     } else {
00054       *blocksize =_blocksize;
00055     }
00056     ++(*start);
00057     *lastusedrank=_lastusedrank;
00058     printf("My rank %d, start %l, stride %l, blocksize %l, count %l, lastblocksize %l\n",myrank,*start,*stride,*blocksize,*count,*lastblocksize);
00059     return;
00060 }
00061 
00062 void getCyclicBlocksOfEntities(const int myrank, const int nproc, const int nbofentities,
00063                                  med_size * const start, med_size * const stride,  med_size * const io_count, med_size * blocksize,
00064                                  int * const lastusedrank, med_size * const lastblocksize ) {
00065 
00066     int      _nusedproc      = nproc;
00067     int      _lastusedrank   = nproc-1;
00068     int      _nblocks_pproc  = *io_count;
00069     int      _nblocks        = _nblocks_pproc*nproc;
00070     med_size _blocksize      = 0;
00071 
00072     if (_nblocks) _blocksize=nbofentities/_nblocks;
00073 
00074     for (; (_blocksize < 1) && ( _nblocks_pproc > 1 ) ; ) {
00075       --_nblocks_pproc;
00076       _nblocks   = _nblocks_pproc*nproc;
00077       _blocksize = nbofentities/_nblocks;
00078     }
00079 
00080 /*     ISCRUTE(_nblocks_pproc); */
00081 /*     ISCRUTE(_blocksize); */
00082 
00083     if ( _blocksize == 0 ) {
00084       MESSAGE("Downcasting getCyclicBlocksOfEntities by getContinuousBlocksOfEntities");
00085       getContinuousBlocksOfEntities(myrank, nproc, nbofentities,
00086                                     start, stride, io_count, blocksize, lastusedrank, lastblocksize );
00087       return;
00088     }
00089 
00090     *blocksize     = _blocksize;
00091     *stride        = _blocksize*nproc;
00092     *start         = _blocksize*myrank;
00093     *io_count      = _nblocks_pproc;
00094 
00095     if (myrank == _lastusedrank) {
00096       *lastblocksize = nbofentities + _blocksize*(1-_nusedproc*_nblocks_pproc);
00097       if ( _nblocks_pproc == 1 ) *blocksize=*lastblocksize;
00098     } else
00099       *lastblocksize=0;
00100 
00101     ++(*start);
00102     *lastusedrank=_lastusedrank;
00103 /*     printf("My rank %d, start %d, stride %d, blocksize %d, io_count %d, lastblocksize %d\n",myrank,*start,*stride,*blocksize,*io_count,*lastblocksize); */
00104     return;
00105 }
00106 
00107 
00108 
00109 
00110 
00111 

Généré le Mon May 16 17:10:22 2011 pour MED fichier par  doxygen 1.6.1