1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <cppunit/extensions/HelperMacros.h>
22 #include "MPI2Connector.hxx"
23 #include "ParaMESH.hxx"
24 #include "ParaFIELD.hxx"
25 #include "MEDCouplingUMesh.hxx"
26 #include "MEDCouplingFieldDouble.hxx"
27 #include "InterpKernelDEC.hxx"
28 #include "MPIProcessorGroup.hxx"
29 #include "CommInterface.hxx"
35 class MPI2ParaMEDMEMTest : public CppUnit::TestFixture
37 CPPUNIT_TEST_SUITE( MPI2ParaMEDMEMTest );
38 CPPUNIT_TEST( testBasicMPI2_1 );
39 CPPUNIT_TEST_SUITE_END();
41 void testBasicMPI2_1();
44 using namespace ParaMEDMEM;
46 void MPI2ParaMEDMEMTest::testBasicMPI2_1()
48 int lsize, lrank, gsize, grank;
50 std::string service = "SERVICE";
51 std::ostringstream meshfilename, meshname;
52 ParaMEDMEM::ParaMESH *paramesh=0;
53 ParaMEDMEM::MEDCouplingUMesh *mesh;
54 ParaMEDMEM::ParaFIELD *parafield=0;
55 ParaMEDMEM::CommInterface *interface;
56 ParaMEDMEM::MPIProcessorGroup *source, *target;
58 MPI_Comm_size( MPI_COMM_WORLD, &lsize );
59 MPI_Comm_rank( MPI_COMM_WORLD, &lrank );
62 CPPUNIT_ASSERT(false);
66 /* Connection to remote programm */
67 MPI2Connector *mpio = new MPI2Connector;
68 gcom = mpio->remoteMPI2Connect(service);
69 MPI_Comm_size( gcom, &gsize );
70 MPI_Comm_rank( gcom, &grank );
73 CPPUNIT_ASSERT(false);
76 interface = new ParaMEDMEM::CommInterface;
77 source = new ParaMEDMEM::MPIProcessorGroup(*interface,0,lsize-1,gcom);
78 target = new ParaMEDMEM::MPIProcessorGroup(*interface,lsize,gsize-1,gcom);
80 const double sourceCoordsAll[2][8]={{0.4,0.5,0.4,1.5,1.6,1.5,1.6,0.5},
81 {0.3,-0.5,1.6,-0.5,1.6,-1.5,0.3,-1.5}};
83 int conn4All[8]={0,1,2,3,4,5,6,7};
85 std::ostringstream stream; stream << "sourcemesh2D proc " << grank;
86 mesh=MEDCouplingUMesh::New(stream.str().c_str(),2);
87 mesh->allocateCells(2);
88 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn4All);
89 mesh->finishInsertingCells();
90 DataArrayDouble *myCoords=DataArrayDouble::New();
92 const double *sourceCoords=sourceCoordsAll[grank];
93 std::copy(sourceCoords,sourceCoords+8,myCoords->getPointer());
94 mesh->setCoords(myCoords);
96 paramesh=new ParaMESH(mesh,*source,"source mesh");
97 ParaMEDMEM::ComponentTopology comptopo;
98 parafield = new ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo);
99 double *value=parafield->getField()->getArray()->getPointer();
100 value[0]=34+13*((double)grank);
102 ParaMEDMEM::InterpKernelDEC dec(*source,*target);
103 parafield->getField()->setNature(ConservativeVolumic);
107 dec.attachLocalField(parafield);
109 dec.setForcedRenormalization(false);
111 /* Deconnection of remote programm */
112 mpio->remoteMPI2Disconnect(service);
123 CPPUNIT_TEST_SUITE_REGISTRATION( MPI2ParaMEDMEMTest );
125 #include "MPIMainTest.hxx"