Back to index

salome-med  6.5.0
MEDSPLITTER_SCOTCHGraph.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 #include <cstdio>
00020 extern "C" {
00021 #define restrict
00022 #include "scotch.h"
00023 }
00024 #include "MEDSPLITTER_Graph.hxx"
00025 #include "MEDSPLITTER_SCOTCHGraph.hxx"
00026 
00027 using namespace MEDSPLITTER;
00028   
00029 SCOTCHGraph::SCOTCHGraph():Graph()
00030 {
00031 }
00032 
00033 SCOTCHGraph::SCOTCHGraph(MEDMEM::MEDSKYLINEARRAY* graph, int* edgeweight):Graph(graph,edgeweight)
00034 {
00035 }
00036 
00037 SCOTCHGraph::~SCOTCHGraph()
00038 {
00039 }
00040 
00041 void SCOTCHGraph::partGraph(int ndomain, const string& options_string, ParaDomainSelector* sel)
00042 {
00043   // number of graph vertices
00044   int n = m_graph->getNumberOf();
00045 
00046   //graph
00047   int * xadj=const_cast<int*>(m_graph->getIndex());
00048   int * adjncy = const_cast<int*>(m_graph->getValue());
00049 
00050   //ndomain
00051   int nparts = ndomain;
00052 
00053   // output parameters
00054   int* partition = new int[n+1];
00055 
00056   SCOTCH_Graph scotch_graph;
00057 
00058   SCOTCH_graphInit(&scotch_graph);
00059 
00060 
00061   SCOTCH_graphBuild(&scotch_graph,
00062                     1, //premier indice 1
00063                     n, // nb of graph nodes
00064                     xadj,
00065                     0,
00066                     m_cellweight, //graph vertices loads
00067                     0,
00068                     xadj[n], // number of edges
00069                     adjncy,
00070                     m_edgeweight);
00071 
00072   SCOTCH_Strat scotch_strategy;           
00073   SCOTCH_stratInit(&scotch_strategy);
00074 
00076   if (options_string!="")
00077     SCOTCH_stratGraphMap(&scotch_strategy,options_string.c_str());
00078 
00079 
00080   if (nparts>1)           
00081     SCOTCH_graphPart(&scotch_graph,nparts,&scotch_strategy,partition);
00082   else
00083     // partition for 1 subdomain
00084     for (int i=0; i<n+1; i++)
00085       partition[i]=0;
00086 
00087   SCOTCH_stratExit(&scotch_strategy);
00088   SCOTCH_graphExit(&scotch_graph);
00089 
00090   int* index=new int [n+1];
00091   index[0]=1;
00092   for (int i=0; i<n; i++)
00093   {
00094     index[i+1]=index[i]+1;
00095   }
00096 
00097   //creating a skylinearray with no copy of the index and partition array
00098   // the fifth argument true specifies that only the pointers are passed 
00099   //to the object
00100   m_partition = new MEDMEM::MEDSKYLINEARRAY(n,n, index, partition, true);
00101 }