1 // Copyright (C) 2007-2008 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.
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
19 #include "ParaMEDMEMTest.hxx"
20 #include <cppunit/TestAssert.h>
22 #include "InterpolationUtils.hxx"
23 #include "CommInterface.hxx"
24 #include "ProcessorGroup.hxx"
25 #include "MPIProcessorGroup.hxx"
26 #include "Topology.hxx"
27 #include "BlockTopology.hxx"
31 // use this define to enable lines, execution of which leads to Segmentation Fault
34 // use this define to enable CPPUNIT asserts and fails, showing bugs
35 #define ENABLE_FORCED_FAILURES
39 using namespace ParaMEDMEM;
42 * Check methods defined in BlockTopology.hxx
45 BlockTopology(const ProcessorGroup& group, const MEDMEM::GRID& grid);
46 BlockTopology(const BlockTopology& geom_topo, const ComponentTopology& comp_topo);
47 (+) BlockTopology(const ProcessorGroup& group, int nb_elem);
48 virtual ~BlockTopology();
49 (+) inline int getNbElements()const;
50 (+) inline int getNbLocalElements() const;
51 const ProcessorGroup* getProcGroup()const {return _proc_group;};
52 (+) inline std::pair<int,int> globalToLocal (const int) const ;
53 (+) inline int localToGlobal (const std::pair<int,int>) const;
54 (+) std::vector<std::pair<int,int> > getLocalArrayMinMax() const ;
55 (+) int getDimension() const {return _dimension;};
56 (+) void serialize(int* & serializer, int& size) const ;
57 (+) void unserialize(const int* serializer, const CommInterface& comm_interface);
61 void ParaMEDMEMTest::testBlockTopology_constructor()
65 MPI_Comm_size(MPI_COMM_WORLD,&size);
67 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
68 CommInterface interface;
69 MPIProcessorGroup group(interface);
70 BlockTopology blocktopo(group,1);
71 CPPUNIT_ASSERT_EQUAL(1,blocktopo.getNbLocalElements());
72 CPPUNIT_ASSERT_EQUAL(size,blocktopo.getNbElements());
73 CPPUNIT_ASSERT_EQUAL(1,blocktopo.getDimension());
75 //checking access methods
76 BlockTopology blocktopo2(group,2);
77 std::pair<int,int> local= blocktopo2.globalToLocal(0);
78 CPPUNIT_ASSERT_EQUAL(local.first,0);
79 CPPUNIT_ASSERT_EQUAL(local.second,0);
80 int global=blocktopo2.localToGlobal(local);
81 CPPUNIT_ASSERT_EQUAL(global,0);
83 local = blocktopo2.globalToLocal(1);
84 CPPUNIT_ASSERT_EQUAL(local.first,0);
85 CPPUNIT_ASSERT_EQUAL(local.second,1);
86 global=blocktopo2.localToGlobal(local);
87 CPPUNIT_ASSERT_EQUAL(global,1);
89 local = blocktopo2.globalToLocal(2*size-1);
90 CPPUNIT_ASSERT_EQUAL(local.first,size-1);
91 CPPUNIT_ASSERT_EQUAL(local.second,1);
92 global=blocktopo2.localToGlobal(local);
93 CPPUNIT_ASSERT_EQUAL(global,2*size-1);
95 std::vector<std::pair<int,int> > bounds = blocktopo2.getLocalArrayMinMax();
96 int vecsize = bounds.size();
97 CPPUNIT_ASSERT_EQUAL(1,vecsize);
98 CPPUNIT_ASSERT_EQUAL(2*rank, (bounds[0]).first);
99 CPPUNIT_ASSERT_EQUAL(2*rank+2, (bounds[0]).second);
102 void ParaMEDMEMTest::testBlockTopology_serialize()
106 MPI_Comm_size(MPI_COMM_WORLD,&size);
108 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
109 CommInterface interface;
110 MPIProcessorGroup group(interface);
111 BlockTopology blocktopo(group,3);
113 //testing the serialization process that is used to transfer a
114 //block topology via a MPI_Send/Recv comm
115 BlockTopology blocktopo_recv;
118 blocktopo.serialize(serializer,sersize);
119 blocktopo_recv.unserialize(serializer,interface);
120 CPPUNIT_ASSERT_EQUAL(blocktopo.getNbElements(),blocktopo_recv.getNbElements());
121 delete [] serializer;