Back to index

salome-med  6.5.0
ParaMEDMEMTestMPI2_1.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-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 #include <cppunit/extensions/HelperMacros.h>
00021 
00022 #include "MPI2Connector.hxx"
00023 #include "ParaMESH.hxx"
00024 #include "ParaFIELD.hxx"
00025 #include "MEDCouplingUMesh.hxx"
00026 #include "MEDCouplingFieldDouble.hxx"
00027 #include "InterpKernelDEC.hxx"
00028 #include "MPIProcessorGroup.hxx"
00029 #include "CommInterface.hxx"
00030 
00031 #include <mpi.h>
00032 #include <iostream>
00033 #include <stdlib.h>
00034 
00035 class MPI2ParaMEDMEMTest : public CppUnit::TestFixture
00036 {
00037   CPPUNIT_TEST_SUITE( MPI2ParaMEDMEMTest );
00038   CPPUNIT_TEST( testBasicMPI2_1 );
00039   CPPUNIT_TEST_SUITE_END();
00040 public:
00041   void testBasicMPI2_1();
00042 };
00043 
00044 using namespace ParaMEDMEM;
00045 
00046 void MPI2ParaMEDMEMTest::testBasicMPI2_1()
00047 {
00048   int lsize, lrank, gsize, grank;
00049   MPI_Comm gcom;
00050   std::string service = "SERVICE";
00051   std::ostringstream meshfilename, meshname;
00052   ParaMEDMEM::ParaMESH *paramesh=0;
00053   ParaMEDMEM::MEDCouplingUMesh *mesh;
00054   ParaMEDMEM::ParaFIELD *parafield=0;
00055   ParaMEDMEM::CommInterface *interface;
00056   ParaMEDMEM::MPIProcessorGroup *source, *target;
00057 
00058   MPI_Comm_size( MPI_COMM_WORLD, &lsize );
00059   MPI_Comm_rank( MPI_COMM_WORLD, &lrank );
00060   if(lsize!=2)
00061     {
00062       CPPUNIT_ASSERT(false);
00063       return;
00064     }
00065 
00066   /* Connection to remote programm */
00067   MPI2Connector *mpio = new MPI2Connector;
00068   gcom = mpio->remoteMPI2Connect(service);
00069   MPI_Comm_size( gcom, &gsize );
00070   MPI_Comm_rank( gcom, &grank );
00071   if(gsize!=5)
00072     {
00073       CPPUNIT_ASSERT(false);
00074       return;
00075     }
00076   interface = new ParaMEDMEM::CommInterface;
00077   source = new ParaMEDMEM::MPIProcessorGroup(*interface,0,lsize-1,gcom);
00078   target = new ParaMEDMEM::MPIProcessorGroup(*interface,lsize,gsize-1,gcom);
00079 
00080   const double sourceCoordsAll[2][8]={{0.4,0.5,0.4,1.5,1.6,1.5,1.6,0.5},
00081                                       {0.3,-0.5,1.6,-0.5,1.6,-1.5,0.3,-1.5}};
00082   
00083   int conn4All[8]={0,1,2,3,4,5,6,7};
00084   
00085   std::ostringstream stream; stream << "sourcemesh2D proc " << grank;
00086   mesh=MEDCouplingUMesh::New(stream.str().c_str(),2);
00087   mesh->allocateCells(2);
00088   mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn4All);
00089   mesh->finishInsertingCells();
00090   DataArrayDouble *myCoords=DataArrayDouble::New();
00091   myCoords->alloc(4,2);
00092   const double *sourceCoords=sourceCoordsAll[grank];
00093   std::copy(sourceCoords,sourceCoords+8,myCoords->getPointer());
00094   mesh->setCoords(myCoords);
00095   myCoords->decrRef();
00096   paramesh=new ParaMESH(mesh,*source,"source mesh");
00097   ParaMEDMEM::ComponentTopology comptopo;
00098   parafield = new ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo);
00099   double *value=parafield->getField()->getArray()->getPointer();
00100   value[0]=34+13*((double)grank);
00101 
00102   ParaMEDMEM::InterpKernelDEC dec(*source,*target);
00103   parafield->getField()->setNature(ConservativeVolumic);
00104 
00105 
00106   dec.setMethod("P0");
00107   dec.attachLocalField(parafield);
00108   dec.synchronize();
00109   dec.setForcedRenormalization(false);
00110   dec.sendData();
00111   /* Deconnection of remote programm */
00112   mpio->remoteMPI2Disconnect(service);
00113   /* clean-up */
00114   delete mpio;
00115   delete parafield;
00116   mesh->decrRef();
00117   delete paramesh;
00118   delete source;
00119   delete target;
00120   delete interface;
00121 }
00122 
00123 CPPUNIT_TEST_SUITE_REGISTRATION( MPI2ParaMEDMEMTest );
00124 
00125 #include "MPIMainTest.hxx"