#include <iostream>
-#ifdef MED_ENABLE_PARMETIS
-#include <mpi.h>
-#include "parmetis.h"
-#endif
-
#ifdef MED_ENABLE_METIS
extern "C"
{
ParaDomainSelector *parallelizer)
{
using std::vector;
- vector<int> ran,vx,va; //for randomize
-
if (MyGlobals::_Verbose>10)
std::cout << "proc " << MyGlobals::_Rank << " : METISGraph::partGraph" << std::endl;
int edgecut;
int* partition=new int[n];
+#if !defined(MED_ENABLE_METIS)
+ throw INTERP_KERNEL::Exception("METISGraph::partGraph : METIS is not available. Check your products, please.");
+#else
if(nparts >1)
{
- if(parallelizer)
- {
-#ifdef MED_ENABLE_PARMETIS
- // distribution of vertices of the graph among the processors
- if (MyGlobals::_Verbose>100)
- std::cout << "proc " << MyGlobals::_Rank << " : METISGraph::partGraph ParMETIS_PartKway" << std::endl;
- int * vtxdist=parallelizer->getProcVtxdist();
- MPI_Comm comm=MPI_COMM_WORLD;
- try
- {
- if (MyGlobals::_Verbose>200)
- {
- std::cout << "proc " << MyGlobals::_Rank << " : vtxdist :";
- for (int i=0; i<MyGlobals::_World_Size+1; ++i)
- std::cout << vtxdist[i] <<" ";
- std::cout << std::endl;
-
- int lgxadj=vtxdist[MyGlobals::_Rank+1]-vtxdist[MyGlobals::_Rank];
-
- if (lgxadj>0)
- {
- std::cout<< "\nproc " << MyGlobals::_Rank << " : lgxadj " << lgxadj << " lgadj " << xadj[lgxadj] << std::endl;
- for (int i=0; i<10; ++i)
- std::cout << xadj[i] << " ";
- std::cout << "... " << xadj[lgxadj] << std::endl;
- for (int i=0; i<15; ++i)
- std::cout << adjncy[i] << " ";
- int ll=xadj[lgxadj]-1;
- std::cout << "... [" << ll << "] " << adjncy[ll-1] << " " << adjncy[ll] << std::endl;
- int imaxx=0;
- for (int ilgxadj=0; ilgxadj<lgxadj; ilgxadj++)
- {
- int ilg=xadj[ilgxadj+1]-xadj[ilgxadj];
- if(ilg>imaxx)
- imaxx=ilg;
- }
- std::cout<< "\nproc " << MyGlobals::_Rank << " : on " << lgxadj << " cells, max neighbourg number (...for one cell) is " << imaxx << std::endl;
- }
- }
- if ((MyGlobals::_Randomize!=0 || MyGlobals::_Atomize!=0) && MyGlobals::_World_Size==1)
- {
- //randomize initially was for test on ParMETIS error (sometimes)
- //due to : seems no changes int options[4]={1,0,33,0}; //test for a random seed of 33
- //it was keeped
- ran=CreateRandomSize(n);
- RandomizeAdj(&xadj[0],&adjncy[0],ran,vx,va);
- ParMETIS_PartKway(vtxdist, &vx[0], &va[0], vwgt,
- adjwgt, &wgtflag, &base, &nparts, options,
- &edgecut, partition, &comm );
- }
- else
- {
- ParMETIS_PartKway(vtxdist, xadj, adjncy, vwgt,
- adjwgt, &wgtflag, &base, &nparts, options,
- &edgecut, partition, &comm );
- }
-
- /*doc from parmetis.h
- void __cdecl ParMETIS_PartKway(
- idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt,
- idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options,
- int *edgecut, idxtype *part, MPI_Comm *comm);
-
- void __cdecl ParMETIS_V3_PartKway(
- idxtype *vtxdist, idxtype *xadj, idxtype *adjncy, idxtype *vwgt,
- idxtype *adjwgt, int *wgtflag, int *numflag, int *ncon, int *nparts,
- float *tpwgts, float *ubvec, int *options, int *edgecut, idxtype *part,
- MPI_Comm *comm);
- */
-
- }
- catch(...)
- {
- //shit ParMETIS "Error! Key -2 not found!" not catched...
- throw INTERP_KERNEL::Exception("Problem in ParMETIS_PartKway");
- }
-#else
-
-#ifdef MED_ENABLE_METIS
- if (MyGlobals::_Verbose>10)
- std::cout << "proc " << MyGlobals::_Rank << " : METISGraph::partGraph METIS_PartGraph Recursive/Kway" << std::endl;
- if (options_string != "k")
- METIS_PartGraphRecursive(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag,
- &base, &nparts, options, &edgecut, partition);
- else
- METIS_PartGraphKway(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag,
- &base, &nparts, options, &edgecut, partition);
-#else
- throw INTERP_KERNEL::Exception("ParMETIS or METIS is not available. Check your products, please.");
-#endif
-
-#endif
- }
+ if (MyGlobals::_Verbose>10)
+ std::cout << "METISGraph::partGraph METIS_PartGraph METIS_PartGraph(RecursiveOrKway) newww" << std::endl;
+ if (options_string != "k")
+ METIS_PartGraphRecursive(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag,
+ &base, &nparts, options, &edgecut, partition);
else
- {
-#ifdef MED_ENABLE_METIS
- if (MyGlobals::_Verbose>10)
- std::cout << "proc " << MyGlobals::_Rank << " : METISGraph::partGraph METIS_PartGraph Recursive or Kway" << std::endl;
- if (options_string != "k")
- METIS_PartGraphRecursive(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag,
- &base, &nparts, options, &edgecut, partition);
- else
- METIS_PartGraphKway(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag,
- &base, &nparts, options, &edgecut, partition);
-#else
- throw INTERP_KERNEL::Exception("METIS is not available. Check your products, please.");
-#endif
- }
+ METIS_PartGraphKway(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag,
+ &base, &nparts, options, &edgecut, partition);
}
- else
+ else //force this case because METIS send all 1 in value
{
for (int i=0; i<n; i++)
partition[i]=0;
}
-
vector<int> index(n+1);
vector<int> value(n);
index[0]=0;
- if (ran.size()>0 && MyGlobals::_Atomize==0) //there is randomize
+ for (int i=0; i<n; i++)
{
- if (MyGlobals::_Is0verbose>100)
- std::cout << "randomize" << std::endl;
- for (int i=0; i<n; i++)
- {
- index[i+1]=index[i]+1;
- value[ran[i]]=partition[i];
- }
- }
- else
- {
- for (int i=0; i<n; i++)
- {
- index[i+1]=index[i]+1;
- value[i]=partition[i];
- }
+ index[i+1]=index[i]+1;
+ value[i]=partition[i];
}
delete [] partition;
//creating a skylinearray with no copy of the index and partition array
//the fifth argument true specifies that only the pointers are passed
//to the object
-
_partition = new MEDPARTITIONER::SkyLineArray(index,value);
+#endif
}
_mesure_memory(mesure_memory), _init_memory(0), _max_memory(0)
{
#ifdef HAVE_MPI2
- MPI_Comm_size(MPI_COMM_WORLD,&_world_size) ;
- MPI_Comm_rank(MPI_COMM_WORLD,&_rank) ;
+ if (MyGlobals::_Rank==-1)
+ {
+ MPI_Init(0,0); //do once only
+ MPI_Comm_size(MPI_COMM_WORLD,&_world_size) ;
+ MPI_Comm_rank(MPI_COMM_WORLD,&_rank) ;
+ }
+ else
+ {
+ _world_size=MyGlobals::_World_Size;
+ _rank=MyGlobals::_Rank;
+ }
_init_time = MPI_Wtime();
+#else
+ //sequential : no MPI
+ _world_size=1;
+ _rank=0;
+ if (MyGlobals::_Verbose>10)
+ std::cout << "WARNING : ParaDomainSelector contructor without parallel_mode World_Size=1 by default" << std::endl;
#endif
+ MyGlobals::_World_Size=_world_size;
+ MyGlobals::_Rank=_rank;
+
+ if (MyGlobals::_Verbose>200) std::cout << "proc " << MyGlobals::_Rank << " of " << MyGlobals::_World_Size << std::endl;
evaluateMemory();
}
nb_elems[i*2+1] = domain_meshes[i]->getNumberOfNodes();
}
// receive nb of elems from other procs
+ std::vector<int> all_nb_elems;
+ if (MyGlobals::_World_Size==1)
+ {
+ all_nb_elems=nb_elems;
+ }
+ else
+ {
#ifdef HAVE_MPI2
- std::vector<int> all_nb_elems( nb_domains*2 );
- MPI_Allreduce((void*)&nb_elems[0], (void*)&all_nb_elems[0], nb_domains*2,
- MPI_INT, MPI_SUM, MPI_COMM_WORLD);
+ all_nb_elems.resize( nb_domains*2 );
+ MPI_Allreduce((void*)&nb_elems[0], (void*)&all_nb_elems[0], nb_domains*2, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
#else
- std::vector<int> all_nb_elems=nb_elems;
+ throw INTERP_KERNEL::Exception("not(HAVE_MPI2) incompatible with MPI_World_Size>1");
#endif
+ }
int total_nb_cells=0, total_nb_nodes=0;
for (int i=0; i<nb_domains; ++i)
{