TrioCFD 1.9.8
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 Calcule le graphe de connectivite, appelle le partitionneur et remplit elem_part (pour chaque element, numero de la partie qui lui
68 *
69 * est attribuee).
70 *
71 */
72void Partitionneur_Ptscotch::construire_partition(IntVect& elem_part, int& nb_parts_tot) const
73{
74#ifndef PTSCOTCH_
75 Cerr << "Ptscotch is not compiled with this version. Use another partition tool like Tranche." << finl;
77#else
78 if (!ref_domaine_)
79 {
80 Cerr << "Error in Partitionneur_Ptscotch::construire_partition\n";
81 Cerr << " The domain has not been associated" << finl;
82 exit();
83 }
84 if (nb_parties_ <= 0)
85 {
86 Cerr << "Error in Partitionneur_Ptscotch::construire_partition\n";
87 Cerr << " The parts number has not been initialized" << finl;
88 exit();
89 }
90
91 // Cas particulier: si nb_parts == 1, METIS ne veut rien faire...
92 //ToDo: I don't know is that's the case with Ptscotch
93 if (nb_parties_ == 1)
94 {
95
96 int nb_elem = ref_domaine_->nb_elem();
97 elem_part.resize_array(nb_elem);
98 elem_part = 0;
99 return;
100 }
101
102 if (ref_domaine_->nb_elem() == 0)
103 return;
104
105 Cerr << "Partitionneur_Ptscotch::construire_partition" << finl;
106 Cerr << " Construction of graph connectivity..." << finl;
107 Static_Int_Lists graph_elements_perio;
108 //const Domaine& dom = ref_domaine_.valeur();
109 Domain_Graph graph;
110 graph.construire_graph_elem_elem(ref_domaine_.valeur(),
111 use_weights_,
112 graph_elements_perio);
113
114
115 const int n = ref_domaine_->nb_elem();
116 SCOTCH_Num* partition = new SCOTCH_Num[n];
117
118 SCOTCH_randomReset();
119 SCOTCH_Dgraph scotch_graph;
120 SCOTCH_dgraphInit(&scotch_graph, Comm_Group_MPI::get_trio_u_world());
121 SCOTCH_dgraphBuild(&scotch_graph,
122 0, // baseval , base first indice 0
123 n, // vertlocnbr , nb of local graph nodes
124 n, // vertlocmax , should be set to vertlocnbr for graphs without holes
125 graph.xadj.addr(), // vertloctab[vertnbr+1] , index vertex table
126 0, // vendloctab , index end vertex table if disjoint, set to zero
127 graph.ewgts.addr(), //graph.ewgts, // veloloctab , graph vertices loads, set to zero
128 0, // vlblocltab , vertex label array : global vertex index
129 graph.xadj[n], // edgelocnbr , number of edges
130 graph.xadj[n], // edgelocsiz , same as edgelocnbr if edgeloctab is compact
131 graph.adjncy.addr(), // edgeloctab[edgelocnbr], global indexes of edges
132 graph.edgegsttab.addr(), // edgegsttab , optional, should be computed internally, set to zero
133 0); // edloloctab , graph edges loads, set to zero
134 SCOTCH_Strat scotch_strategy;
135 SCOTCH_stratInit(&scotch_strategy);
136
137 SCOTCH_dgraphPart(&scotch_graph,nb_parties_,&scotch_strategy,partition);
138
139 SCOTCH_stratExit(&scotch_strategy);
140 SCOTCH_dgraphExit(&scotch_graph);
141
142 MD_Vector_tools::creer_tableau_distribue(ref_domaine_->md_vector_elements(), elem_part);
143 for (int i = 0; i < n; i++)
144 elem_part[i] = static_cast<int>(partition[i]); // partition[i] is a a proc number...
145
146 delete [] partition;
147
148 // Correction de la partition pour la periodicite. (***)
149 if (graph_elements_perio.get_nb_lists() > 0)
150 {
151 Cerr << "Correction of the partition for the periodicity" << finl;
152 corriger_bords_avec_liste(ref_domaine_.valeur(),
153 0,
154 elem_part);
155 Cerr << " If this number is high, we can improve the splitting with the option use_weights\n"
156 << " but it takes more memory)" << finl;
157 }
158
159 Cerr << "Correction elem0 on processor 0" << finl;
160 corriger_elem0_sur_proc0(elem_part);
161 elem_part.echange_espace_virtuel();
162#endif
163}
164
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)
transforme v en un tableau parallele ayant la structure md.
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
virtual void set_param(Param &) const
Definition Objet_U.h:135
friend class Entree
Definition Objet_U.h:76
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
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 d'un domaine en nb_parties parties equilibrees en utilisant la librairie Ptscotch.
void associer_domaine(const Domaine &domaine) override
int lire_motcle_non_standard(const Motcle &, Entree &) override
Lecture des parametres de type non simple d'un objet_U a partir d'un flot d'entree.
void construire_partition(IntVect &elem_part, int &nb_parts_tot) const override
Calcule le graphe de connectivite, appelle le partitionneur et remplit elem_part (pour chaque 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)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
int_t get_nb_lists() const
renvoie le nombre de listes stockees
_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")