Salome HOME
Various fixes for test runs - introducing MEDCOUPLING_RESOURCE_DIR env variable
[tools/medcoupling.git] / src / MEDPartitioner / MEDPARTITIONER_ParMetisGraph.cxx
index 5e85a6f94bf59bd07da938dbf5fc63837e359ba9..a17bd6f8b8013ec9ab3b145adee15159b3205487 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2020  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#include "MEDPARTITIONER_MetisGraph.hxx"
+#include "MEDPARTITIONER_ParMetisGraph.hxx"
 #include "MEDPARTITIONER_ParaDomainSelector.hxx"
 #include "MEDPARTITIONER_Utils.hxx"
 
+#include "MEDCouplingSkyLineArray.hxx"
 #include "InterpKernelException.hxx"
 
 #include <iostream>
 
 #ifdef MED_ENABLE_PARMETIS
-#include <mpi.h>
-#include "parmetis.h"
+#include <parmetis.h>
+// #if PARMETIS_MAJOR_VERSION == 4
+//    #define ParMETIS_PartKway ParMETIS_V3_PartKway
+// #endif
 #endif
 
 using namespace MEDPARTITIONER;
 
-METISGraph::METISGraph():Graph()
+ParMETISGraph::ParMETISGraph():Graph()
 {
 }
 
-METISGraph::METISGraph(MEDPARTITIONER::SkyLineArray* graph, int* edgeweight)
+ParMETISGraph::ParMETISGraph(MEDCoupling::MEDCouplingSkyLineArray* graph, int* edgeweight)
   :Graph(graph,edgeweight)
 {
 }
 
-METISGraph::~METISGraph()
+ParMETISGraph::~ParMETISGraph()
 {
 }
 
-void METISGraph::partGraph(int ndomain,
+void ParMETISGraph::partGraph(int ndomain,
                            const std::string& options_string,
                            ParaDomainSelector *parallelizer)
 {
@@ -53,13 +56,20 @@ void METISGraph::partGraph(int ndomain,
   vector<int> ran,vx,va; //for randomize
   
   if (MyGlobals::_Verbose>10)
-    std::cout << "proc " << MyGlobals::_Rank << " : METISGraph::partGraph" << std::endl;
+    std::cout << "proc " << MyGlobals::_Rank << " : ParMETISGraph::partGraph" << std::endl;
   
   // number of graph vertices
-  int n=_graph->getNumberOf();
+  int n=FromIdType<int>(_graph->getNumberOf());
   //graph
+#ifdef MEDCOUPLING_USE_64BIT_IDS
+  std::vector<int> indexVec( _graph->getIndex(), _graph->getIndexArray()->end() );
+  std::vector<int> valueVec( _graph->getValues(), _graph->getValuesArray()->end() );
+  int * xadj=indexVec.data();
+  int * adjncy=valueVec.data();
+#else
   int * xadj=const_cast<int*>(_graph->getIndex());
-  int * adjncy=const_cast<int*>(_graph->getValue());
+  int * adjncy=const_cast<int*>(_graph->getValues());
+#endif
   //constraints
   int * vwgt=_cell_weight;
   int * adjwgt=_edge_weight;
@@ -81,12 +91,12 @@ void METISGraph::partGraph(int ndomain,
   // output parameters
   int edgecut;
 #if !defined(MED_ENABLE_PARMETIS)
-  throw INTERP_KERNEL::Exception("METISGraph::partGraph : PARMETIS is not available. Check your products, please.");
+  throw INTERP_KERNEL::Exception("ParMETISGraph::partGraph : PARMETIS is not available. Check your products, please.");
 #else
   int* partition=new int[n];
   
   if (MyGlobals::_Verbose>10) 
-    std::cout << "proc " << MyGlobals::_Rank << " : METISGraph::partGraph ParMETIS_PartKway new" << std::endl;
+    std::cout << "proc " << MyGlobals::_Rank << " : ParMETISGraph::partGraph ParMETIS_PartKway new" << std::endl;
   int * vtxdist=parallelizer->getProcVtxdist();
   MPI_Comm comm=MPI_COMM_WORLD;
   ParMETIS_PartKway(vtxdist, xadj, adjncy, vwgt, 
@@ -107,8 +117,8 @@ void METISGraph::partGraph(int ndomain,
     MPI_Comm *comm);
   */
 
-  vector<int> index(n+1);
-  vector<int> value(n);
+  vector<mcIdType> index(n+1);
+  vector<mcIdType> value(n);
   index[0]=0;
   if (ran.size()>0 && MyGlobals::_Atomize==0) //there is randomize
     {
@@ -117,7 +127,7 @@ void METISGraph::partGraph(int ndomain,
       for (int i=0; i<n; i++)
         {
           index[i+1]=index[i]+1;
-          value[ran[i]]=partition[i];
+          value[ran[i]]=ToIdType(partition[i]);
         }
     }
   else
@@ -125,7 +135,7 @@ void METISGraph::partGraph(int ndomain,
       for (int i=0; i<n; i++)
         {
           index[i+1]=index[i]+1;
-          value[i]=partition[i];
+          value[i]=ToIdType(partition[i]);
         }
     }
   delete [] partition;
@@ -134,7 +144,7 @@ void METISGraph::partGraph(int ndomain,
   //the fifth argument true specifies that only the pointers are passed 
   //to the object
   
-  _partition = new MEDPARTITIONER::SkyLineArray(index,value);
+  _partition = MEDCoupling::MEDCouplingSkyLineArray::New(index,value);
 #endif
 }