Back to index

salome-med  6.5.0
ParaMEDMEMTest_MPIProcessorGroup.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 "ParaMEDMEMTest.hxx"
00021 #include <cppunit/TestAssert.h>
00022 #include "CommInterface.hxx"
00023 #include "ProcessorGroup.hxx"
00024 #include "MPIProcessorGroup.hxx"
00025 #include "InterpolationUtils.hxx"
00026 
00027 #include <string>
00028 
00029 // use this define to enable lines, execution of which leads to Segmentation Fault
00030 #define ENABLE_FAULTS
00031 
00032 // use this define to enable CPPUNIT asserts and fails, showing bugs
00033 #define ENABLE_FORCED_FAILURES
00034 
00035 
00036 using namespace std;
00037 using namespace ParaMEDMEM;
00038  
00039 /*
00040  * Check methods defined in MPPIProcessorGroup.hxx
00041  *
00042  (+) MPIProcessorGroup(const CommInterface& interface);
00043  (+) MPIProcessorGroup(const CommInterface& interface, set<int> proc_ids);
00044  (u) MPIProcessorGroup (const ProcessorGroup& proc_group, set<int> proc_ids);
00045  (+) MPIProcessorGroup(const CommInterface& interface,int pstart, int pend);
00046  (+) virtual ~MPIProcessorGroup();
00047  (+) virtual ProcessorGroup* fuse (const ProcessorGroup&) const;
00048  (u) void intersect (ProcessorGroup&){};
00049  (+) int myRank() const {int rank; MPI_Comm_rank(_comm,&rank); return rank;}
00050  (+) bool containsMyRank() const { int rank; MPI_Group_rank(_group, &rank); return (rank!=MPI_UNDEFINED);}
00051  (+) int translateRank(const ProcessorGroup* group, int rank) const;
00052  (+) const MPI_Comm* getComm() const {return &_comm;}
00053  (+) ProcessorGroup* createComplementProcGroup() const;
00054  (o) ProcessorGroup* createProcGroup() const;
00055    
00056 */
00057  
00058 void ParaMEDMEMTest::testMPIProcessorGroup_constructor()
00059 {
00060   CommInterface comm_interface;
00061   MPIProcessorGroup* group= new MPIProcessorGroup(comm_interface);
00062   int size;
00063   MPI_Comm_size(MPI_COMM_WORLD, &size);
00064   CPPUNIT_ASSERT_EQUAL(size,group->size());
00065   int size2;
00066   const MPI_Comm* communicator=group->getComm();
00067   MPI_Comm_size(*communicator, &size2);
00068   CPPUNIT_ASSERT_EQUAL(size,size2);
00069   delete group;
00070   
00071   set <int> procs;
00072   
00073   procs.insert(0);
00074   procs.insert(1);
00075   if (size==1)
00076     CPPUNIT_ASSERT_THROW(group=new MPIProcessorGroup(comm_interface,procs),INTERP_KERNEL::Exception);
00077   else
00078     {
00079       CPPUNIT_ASSERT_NO_THROW(  group=new MPIProcessorGroup(comm_interface,procs));
00080       CPPUNIT_ASSERT_EQUAL (group->size(),2);
00081       delete group;
00082     }
00083   
00084   
00085   //throws because plast<pfirst
00086   CPPUNIT_ASSERT_THROW(group=new MPIProcessorGroup(comm_interface,1,0),INTERP_KERNEL::Exception);
00087   //throws because plast is beyond size-1
00088   CPPUNIT_ASSERT_THROW(group=new MPIProcessorGroup(comm_interface,0,size),INTERP_KERNEL::Exception);
00089   if (size>1)
00090     {
00091       group=new MPIProcessorGroup(comm_interface,0,size-2);
00092       CPPUNIT_ASSERT_EQUAL(group->size(),size-1);
00093       delete group;
00094     }
00095   
00096 }
00097  
00098 void ParaMEDMEMTest::testMPIProcessorGroup_boolean()
00099 {
00100   int size;
00101   MPI_Comm_size(MPI_COMM_WORLD, &size);
00102   
00103   CommInterface comm_interface;
00104   MPIProcessorGroup group(comm_interface,0,0);
00105   MPIProcessorGroup group2(comm_interface,size-1,size-1);
00106   ProcessorGroup* group_fuse=group.fuse(group2);
00107   int group_fuse_size=(size==1)?1:2;
00108   CPPUNIT_ASSERT_EQUAL(group_fuse_size,group_fuse->size());
00109  
00110   ProcessorGroup* group_complement=((MPIProcessorGroup*)group_fuse)->createComplementProcGroup();
00111   CPPUNIT_ASSERT_EQUAL(group_complement->size(),size-group_fuse_size);
00112   
00113   delete group_fuse;
00114   delete group_complement;
00115 
00116   //intersect not implemented yet
00117   //   if (size>1)
00118   //   {
00119   //     MPIProcessorGroup group3(comm_interface,0,size-2);
00120   //     MPIProcessorGroup group4(comm_interface,1,size-1);
00121   //     group3.intersect(group4);
00122   //     CPPUNIT_ASSERT_EQUAL(group3.size(),size-2);
00123   //   }
00124 }
00125 
00126 void ParaMEDMEMTest::testMPIProcessorGroup_rank()
00127 {
00128   int size;
00129   MPI_Comm_size(MPI_COMM_WORLD, &size);
00130   int rank;
00131   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00132   
00133   CommInterface comm_interface;
00134   MPIProcessorGroup group(comm_interface,0,0);
00135   MPIProcessorGroup group2(comm_interface,size-1,size-1);
00136   ProcessorGroup* group_fuse=group2.fuse(group);
00137   
00138   if (group.containsMyRank())
00139     CPPUNIT_ASSERT_EQUAL (group.myRank(), rank);
00140 
00141   if (group2.containsMyRank())
00142     {
00143       int trank=group_fuse->translateRank(&group2,0);
00144       if (size==1)
00145         CPPUNIT_ASSERT_EQUAL(trank,0);
00146       else  
00147         CPPUNIT_ASSERT_EQUAL(trank,1);
00148     }
00149   delete group_fuse;
00150 }