Back to index

salome-paravis  6.5.0
TestMedParallelRead.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 /*
00021  * TestMedParallelRead.cxx
00022  *
00023  *  Created on: 20 avr. 2011
00024  *      Author: alejandro
00025  */
00026 
00027 #define MAX(a,b) ((a) > (b) ? (a) : (b))
00028 
00029 #define MED_HAVE_MPI
00030 
00031 #include <vtkMed.h>
00032 #define MESGERR 1
00033 #include "med_utils.h"
00034 
00035 #include <stdlib.h>
00036 #include <string.h>
00037 #include <assert.h>
00038 
00039 #if TIME_WITH_SYS_TIME
00040 # include <sys/time.h>
00041 # include <time.h>
00042 #else
00043 # if HAVE_SYS_TIME_H
00044 #  include <sys/time.h>
00045 # else
00046 #  include <time.h>
00047 # endif
00048 #endif
00049 
00050 int main (int argc, char **argv)
00051 {
00052   med_err _ret=0;
00053   med_idt _fid;
00054 
00055   int mpi_size, mpi_rank;
00056   MPI_Comm comm = MPI_COMM_WORLD;
00057   MPI_Info info = MPI_INFO_NULL;
00058 
00059   med_int    _nbofentitiesfiltered=0;
00060   med_int    *_filterarray=NULL;
00061 
00062   MPI_Init(&argc, &argv);
00063   MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
00064   MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
00065 
00066   med_size            _nbblocksperproc    = 0;
00067   int           _nbofentities             = 0;
00068   int           _nbofvaluesperentity      = 0;
00069   int           _nbofconstituentpervalue  = 0;
00070 
00071   printf("mpi_size = %03d\n", mpi_size);
00072 
00073   if (mpi_rank == 0 ) {
00074 
00075     struct tm *_tm ;
00076     time_t _tt=time(0);
00077     _tm = localtime(&_tt);
00078 
00079     srandom((*_tm).tm_sec * (*_tm).tm_min );
00080     _nbblocksperproc         = 1 + (int) (mpi_size * (random() / (RAND_MAX + 1.0)));
00081     _nbofentities            = 1 + (int) (1000.0 * (random() / (RAND_MAX + 1.0)));
00082     _nbofvaluesperentity     = 1 + (int) (11.0 * (random() / (RAND_MAX + 1.0)));
00083     _nbofconstituentpervalue = 1 + (int) (7.0 * (random() / (RAND_MAX + 1.0)));
00084   }
00085 
00086   MPI_Bcast(&_nbblocksperproc         , 1, MPI_LONG, 0, MPI_COMM_WORLD);
00087   MPI_Bcast(&_nbofentities            , 1, MPI_LONG, 0, MPI_COMM_WORLD);
00088   MPI_Bcast(&_nbofvaluesperentity     , 1, MPI_LONG, 0, MPI_COMM_WORLD);
00089   MPI_Bcast(&_nbofconstituentpervalue , 1, MPI_LONG, 0, MPI_COMM_WORLD);
00090 
00091   printf( "NENT-%03d_NVAL-%03d_NCST-%03d_NBL-%03llu\n",_nbofentities,_nbofvaluesperentity,
00092           _nbofconstituentpervalue,_nbblocksperproc);
00093 
00094   char         _filename   [255]="";
00095   sprintf(_filename,"/home/alejandro/work/Data-test-Med/tmp/depl.resu.med");
00096   /*     SSCRUTE(_filename); */
00097 
00098   /* Ouverture du fichier en mode parallel */
00099   if ((_fid = MEDparFileOpen(_filename, MED_ACC_RDONLY ,comm, info)) < 0){
00100     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,_filename);
00101   }
00102 
00103   if ( MEDfileClose( _fid ) < 0) {
00104       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILE,""); _ret = -1;
00105     }
00106 
00107   /* MPI_Finalize must be called AFTER MEDclose which may use MPI calls */
00108   MPI_Finalize();
00109 
00110 }