#include "ParaMEDMEMTest.hxx"
#include "MEDLoader.hxx"
-#include "MEDCouplingUMesh.hxx"
+
+#include "ParaMEDFileMesh.hxx"
+#include "MEDFileMesh.hxx"
+#include "MEDFileField1TS.hxx"
+#include "TestInterpKernelUtils.hxx"
#include "MEDCouplingFieldDouble.hxx"
#include <cppunit/TestAssert.h>
#include <iostream>
#include <iterator>
-using namespace std;
-using namespace INTERP_KERNEL;
using namespace MEDCoupling;
+MEDCouplingUMesh* genLocMesh(int rk)
+{
+ int nxTot=4,nyTot=2;
+ int nx=2,ny=2;
+ MCAuto<MEDCouplingCMesh> msh = MEDCouplingCMesh::New("mesh");
+ MCAuto<DataArrayDouble> dax = DataArrayDouble::New(); dax->alloc(nx+1,1);
+ MCAuto<DataArrayDouble> day = DataArrayDouble::New(); day->alloc(ny+1,1);
+ dax->iota(); day->iota();
+ if (rk == 0)
+ {
+ std::transform(dax->begin(), dax->end(),
+ dax->rwBegin(),
+ [nxTot](const int& c){return c/(float)nxTot;});
+ std::transform(day->begin(), day->end(),
+ day->rwBegin(),
+ [nyTot](const int& c){return c/(float)nyTot;});
+ }
+ else
+ {
+ std::transform(dax->begin(), dax->end(),
+ dax->rwBegin(),
+ [nxTot](const int& c){return c/(float)nxTot+0.5; });
+ std::transform(day->begin(), day->end(),
+ day->rwBegin(),
+ [nyTot](const int& c){return c/(float)nyTot;});
+ }
+ msh->setCoords(dax, day);
+ MCAuto<MEDCouplingUMesh> ret = msh->buildUnstructured();
+ return ret.retn();
+}
+
+MEDCouplingFieldDouble *genLocField(int rank)
+{
+ MCAuto<MEDCouplingUMesh> mesh = genLocMesh(rank);
+ MCAuto<MEDCouplingFieldDouble> f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
+ f1->setName("field");
+ f1->setMesh(mesh);
+
+ MCAuto<DataArrayDouble> array(DataArrayDouble::New());
+ double* values = new double[4];
+ if(rank == 0)
+ values[0]= 0.,values[1]=10.,values[2]=40.,values[3]=50.;
+ else
+ values[0]=20.,values[1]=30.,values[2]=60.,values[3]=70.;
+ array->useArray(values,true, DeallocType::CPP_DEALLOC,4,1);
+ array->setInfoOnComponent(0,"s");
+ f1->setArray(array);
+ return f1.retn();
+}
+
+
+void ParaMEDMEMTest::testParallelLoad1()
+{
+ int size;
+ int rank;
+ MPI_Comm_size(MPI_COMM_WORLD,&size);
+ MPI_Comm_rank(MPI_COMM_WORLD,&rank);
+ //
+ if(size!=2)
+ return ;
+
+ std::vector<mcIdType> distrib;
+ if (rank == 0)
+ distrib = {0,1,4,5}; //c++ type of indexing: index starts from zero!
+ else
+ distrib = {2,3,6,7};
+
+ std::string filename=INTERP_TEST::getResourceFile("SimpleTest2D.med");
+ MCAuto<MEDFileUMesh> mu = ParaMEDFileUMesh::ParaNew(distrib, MPI_COMM_WORLD, MPI_INFO_NULL, filename, "mesh");
+ MCAuto<MEDCouplingUMesh> meshRef = genLocMesh(rank);
+ CPPUNIT_ASSERT(mu->getMeshAtLevel(0)->isEqual(meshRef,1e-12));
+ MPI_Barrier(MPI_COMM_WORLD);
+
+}
+
+
+void ParaMEDMEMTest::testParallelLoad2()
+{
+ int size;
+ int rank;
+ MPI_Comm_size(MPI_COMM_WORLD,&size);
+ MPI_Comm_rank(MPI_COMM_WORLD,&rank);
+ //
+ if(size!=2)
+ return ;
+
+ std::vector<mcIdType> distrib;
+ if (rank == 0)
+ distrib = {0,1,4,5}; //c++ type of indexing: index starts from zero!
+ else
+ distrib = {2,3,6,7};
+
+ std::string filename=INTERP_TEST::getResourceFile("SimpleTest2D.med");
+ MCAuto<MEDFileUMesh> mu = ParaMEDFileUMesh::ParaNew(distrib, MPI_COMM_WORLD, MPI_INFO_NULL, filename, "mesh");
+ MCAuto<MEDFileField1TS> f1TS = ParaMEDFileField1TS::ParaNew(mu, filename, "mesh", "field");
+ MCAuto<MEDCouplingFieldDouble> partField = f1TS->field(mu);
+ MCAuto<MEDCouplingFieldDouble> fieldRef = genLocField(rank);
+ CPPUNIT_ASSERT_EQUAL(4,(int)partField->getNumberOfTuples());
+ CPPUNIT_ASSERT(partField->getArray()->isEqual(*fieldRef->getArray(),1e-12));
+ MPI_Barrier(MPI_COMM_WORLD);
+}
+