TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Partitionneur_Ptscotch.cpp
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15#include <Partitionneur_Ptscotch.h>
16#include <Domaine.h>
17#include <Static_Int_Lists.h>
18#include <ptscotch++.h>
19#include <Param.h>
20#include <Domain_Graph.h>
21#include <communications.h>
22#include <Poly_geom_base.h>
23#include <Matrix_tools.h>
24#include <Matrice_Morse.h>
25#include <Array_tools.h>
26#include <Comm_Group_MPI.h>
27#include <MD_Vector_tools.h>
28
29
30inline void not_implemented(const Nom& chaine)
31{
32 Cerr << chaine << " is not implemented yet to the Ptscotch API." << finl;
34}
35
36Implemente_instanciable_sans_constructeur(Partitionneur_Ptscotch,"Partitionneur_Ptscotch",Partitionneur_base);
37
38Partitionneur_Ptscotch::Partitionneur_Ptscotch()
39{
40}
41
43{
44 Cerr << "Partitionneur_Ptscotch::printOn invalid\n" << finl;
45 exit();
46 return os;
47}
48
49
51{
52 param.ajouter("nb_parts",&nb_parties_,Param::REQUIRED);
53 param.ajouter_condition("(value_of_nb_parts_ge_1)_and_(value_of_nb_parts_le_100000)","The following condition must be satisfied : 1 <= nb_parties <= 100000");
54 param.ajouter_flag("use_weights",&use_weights_);
55}
56
61
62void Partitionneur_Ptscotch::associer_domaine(const Domaine& domaine)
63{
64 ref_domaine_ = domaine;
65}
66
67/*! @brief @brief Computes the connectivity graph, calls the partitioner and fills elem_part (for each element, the number of the part assigned to it).
68 *
69 */
70void Partitionneur_Ptscotch::construire_partition(IntVect& elem_part, int& nb_parts_tot) const
71{
72#ifndef PTSCOTCH_
73 Cerr << "Ptscotch is not compiled with this version. Use another partition tool like Tranche." << finl;
75#else
76 if (!ref_domaine_)
77 {
78 Cerr << "Error in Partitionneur_Ptscotch::construire_partition\n";
79 Cerr << " The domain has not been associated" << finl;
80 exit();
81 }
82 if (nb_parties_ <= 0)
83 {
84 Cerr << "Error in Partitionneur_Ptscotch::construire_partition\n";
85 Cerr << " The parts number has not been initialized" << finl;
86 exit();
87 }
88
89 // Special case: if nb_parts == 1, METIS does nothing...
90 //ToDo: I don't know is that's the case with Ptscotch
91 if (nb_parties_ == 1)
92 {
93
94 int nb_elem = ref_domaine_->nb_elem();
95 elem_part.resize_array(nb_elem);
96 elem_part = 0;
97 return;
98 }
99
100 if (ref_domaine_->nb_elem() == 0)
101 return;
102
103 Cerr << "Partitionneur_Ptscotch::construire_partition" << finl;
104 Cerr << " Construction of graph connectivity..." << finl;
105 Static_Int_Lists graph_elements_perio;
106 //const Domaine& dom = ref_domaine_.valeur();
107 Domain_Graph graph;
108 graph.construire_graph_elem_elem(ref_domaine_.valeur(),
109 use_weights_,
110 graph_elements_perio);
111
112
113 const int n = ref_domaine_->nb_elem();
114 SCOTCH_Num* partition = new SCOTCH_Num[n];
115
116 SCOTCH_randomReset();
117 SCOTCH_Dgraph scotch_graph;
118 SCOTCH_dgraphInit(&scotch_graph, Comm_Group_MPI::get_trio_u_world());
119 SCOTCH_dgraphBuild(&scotch_graph,
120 0, // baseval , base first index 0
121 n, // vertlocnbr , nb of local graph nodes
122 n, // vertlocmax , should be set to vertlocnbr for graphs without holes
123 graph.xadj.addr(), // vertloctab[vertnbr+1] , index vertex table
124 0, // vendloctab , index end vertex table if disjoint, set to zero
125 graph.ewgts.addr(), //graph.ewgts, // veloloctab , graph vertices loads, set to zero
126 0, // vlblocltab , vertex label array : global vertex index
127 graph.xadj[n], // edgelocnbr , number of edges
128 graph.xadj[n], // edgelocsiz , same as edgelocnbr if edgeloctab is compact
129 graph.adjncy.addr(), // edgeloctab[edgelocnbr], global indexes of edges
130 graph.edgegsttab.addr(), // edgegsttab , optional, should be computed internally, set to zero
131 0); // edloloctab , graph edges loads, set to zero
132 SCOTCH_Strat scotch_strategy;
133 SCOTCH_stratInit(&scotch_strategy);
134
135 SCOTCH_dgraphPart(&scotch_graph,nb_parties_,&scotch_strategy,partition);
136
137 SCOTCH_stratExit(&scotch_strategy);
138 SCOTCH_dgraphExit(&scotch_graph);
139
140 MD_Vector_tools::creer_tableau_distribue(ref_domaine_->md_vector_elements(), elem_part);
141 for (int i = 0; i < n; i++)
142 elem_part[i] = static_cast<int>(partition[i]); // partition[i] is a a proc number...
143
144 delete [] partition;
145
146 // Correction of the partition for periodicity. (***)
147 if (graph_elements_perio.get_nb_lists() > 0)
148 {
149 Cerr << "Correction of the partition for the periodicity" << finl;
150 corriger_bords_avec_liste(ref_domaine_.valeur(),
151 0,
152 elem_part);
153 Cerr << " If this number is high, we can improve the splitting with the option use_weights\n"
154 << " but it takes more memory)" << finl;
155 }
156
157 Cerr << "Correction elem0 on processor 0" << finl;
158 corriger_elem0_sur_proc0(elem_part);
159 elem_part.echange_espace_virtuel();
160#endif
161}
162
Build the graph of the domain that the METIS/PARMETIS/PTSCOTCH libraries need.
ArrOfIdx_ edgegsttab
void construire_graph_elem_elem(const Domaine_32_64< _SIZE_ > &dom, bool use_weights, Static_Int_Lists_32_64< _SIZE_ > &graph_elements_perio)
ArrOfIdx_ ewgts
ArrOfIdx_ adjncy
ArrOfIdx_ xadj
static void creer_tableau_distribue(const MD_Vector &, Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Transforms v into a parallel array having the structure md.
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
virtual void set_param(Param &) const
Definition Objet_U.h:130
friend class Entree
Definition Objet_U.h:71
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
void ajouter_flag(const char *keyword, const bool *value)
Register a boolean flag whose mere presence switches it to true.
Definition Param.cpp:474
void ajouter_condition(const char *condition, const char *message, const char *name=0)
Declare a post-read logical condition that must hold on the parameter values.
Definition Param.cpp:496
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
Definition Param.cpp:364
@ REQUIRED
Definition Param.h:115
Partition of a domain into nb_parties balanced parts using the Ptscotch library.
void associer_domaine(const Domaine &domaine) override
int lire_motcle_non_standard(const Motcle &, Entree &) override
Reads non-simple-type parameters of an Objet_U from an input stream.
void construire_partition(IntVect &elem_part, int &nb_parts_tot) const override
Computes the connectivity graph, calls the partitioner and fills elem_part (for each element,...
int lire_motcle_non_standard(const Motcle &, Entree &) override
static void corriger_bords_avec_liste(const Domaine_t &dom, const int_t my_offset, BigIntVect_ &elem_part)
static void corriger_elem0_sur_proc0(BigIntVect_ &elem_part)
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
Definition Sortie.h:52
int_t get_nb_lists() const
Returns the number of stored lists.
_TYPE_ * addr()
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")