Salome HOME
81b1bddda0021c74fa84c478b9d1ee567e9ec6e0
[modules/paravis.git] / src / Plugins / MEDReader / IO / Testing / Cxx / TestMedParallelRead.cxx
1 // Copyright (C) 2010-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 /*
21  * TestMedParallelRead.cxx
22  *
23  *  Created on: 20 avr. 2011
24  *      Author: alejandro
25  */
26
27 #define MAX(a,b) ((a) > (b) ? (a) : (b))
28
29 #define MED_HAVE_MPI
30
31 #include <vtkMed.h>
32 #define MESGERR 1
33 #include "med_utils.h"
34
35 #include <stdlib.h>
36 #include <string.h>
37 #include <assert.h>
38
39 #if TIME_WITH_SYS_TIME
40 # include <sys/time.h>
41 # include <time.h>
42 #else
43 # if HAVE_SYS_TIME_H
44 #  include <sys/time.h>
45 # else
46 #  include <time.h>
47 # endif
48 #endif
49
50 int main (int argc, char **argv)
51 {
52   med_err _ret=0;
53   med_idt _fid;
54
55   int mpi_size, mpi_rank;
56   MPI_Comm comm = MPI_COMM_WORLD;
57   MPI_Info info = MPI_INFO_NULL;
58
59   med_int    _nbofentitiesfiltered=0;
60   med_int    *_filterarray=NULL;
61
62   MPI_Init(&argc, &argv);
63   MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
64   MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
65
66   med_size            _nbblocksperproc    = 0;
67   int           _nbofentities             = 0;
68   int           _nbofvaluesperentity      = 0;
69   int           _nbofconstituentpervalue  = 0;
70
71   printf("mpi_size = %03d\n", mpi_size);
72
73   if (mpi_rank == 0 ) {
74
75     struct tm *_tm ;
76     time_t _tt=time(0);
77     _tm = localtime(&_tt);
78
79     srandom((*_tm).tm_sec * (*_tm).tm_min );
80     _nbblocksperproc         = 1 + (int) (mpi_size * (random() / (RAND_MAX + 1.0)));
81     _nbofentities            = 1 + (int) (1000.0 * (random() / (RAND_MAX + 1.0)));
82     _nbofvaluesperentity     = 1 + (int) (11.0 * (random() / (RAND_MAX + 1.0)));
83     _nbofconstituentpervalue = 1 + (int) (7.0 * (random() / (RAND_MAX + 1.0)));
84   }
85
86   MPI_Bcast(&_nbblocksperproc         , 1, MPI_LONG, 0, MPI_COMM_WORLD);
87   MPI_Bcast(&_nbofentities            , 1, MPI_LONG, 0, MPI_COMM_WORLD);
88   MPI_Bcast(&_nbofvaluesperentity     , 1, MPI_LONG, 0, MPI_COMM_WORLD);
89   MPI_Bcast(&_nbofconstituentpervalue , 1, MPI_LONG, 0, MPI_COMM_WORLD);
90
91   printf( "NENT-%03d_NVAL-%03d_NCST-%03d_NBL-%03llu\n",_nbofentities,_nbofvaluesperentity,
92           _nbofconstituentpervalue,_nbblocksperproc);
93
94   char         _filename   [255]="";
95   sprintf(_filename,"/home/alejandro/work/Data-test-Med/tmp/depl.resu.med");
96   /*     SSCRUTE(_filename); */
97
98   /* Ouverture du fichier en mode parallel */
99   if ((_fid = MEDparFileOpen(_filename, MED_ACC_RDONLY ,comm, info)) < 0){
100     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,_filename);
101   }
102
103   if ( MEDfileClose( _fid ) < 0) {
104       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILE,""); _ret = -1;
105     }
106
107   /* MPI_Finalize must be called AFTER MEDclose which may use MPI calls */
108   MPI_Finalize();
109
110 }