35#error This example requires that MFEM is built with MFEM_USE_AMGX=YES
38int main(
int argc,
char *argv[])
47 const char *mesh_file =
"../../data/star.mesh";
49 bool static_cond =
false;
51 const char *device_config =
"cpu";
52 bool visualization =
true;
54 bool amgx_mpi_teams =
false;
55 const char* amgx_json_file =
"";
59 args.
AddOption(&mesh_file,
"-m",
"--mesh",
62 "Finite element order (polynomial degree) or -1 for"
63 " isoparametric space.");
64 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
65 "--no-static-condensation",
"Enable static condensation.");
66 args.
AddOption(&pa,
"-pa",
"--partial-assembly",
"-no-pa",
67 "--no-partial-assembly",
"Enable Partial Assembly.");
68 args.
AddOption(&amgx_lib,
"-amgx",
"--amgx-lib",
"-no-amgx",
69 "--no-amgx-lib",
"Use AmgX in example.");
70 args.
AddOption(&amgx_json_file,
"--amgx-file",
"--amgx-file",
71 "AMGX solver config file (overrides --amgx-solver, --amgx-verbose)");
72 args.
AddOption(&amgx_mpi_teams,
"--amgx-mpi-teams",
"--amgx-mpi-teams",
73 "--amgx-mpi-gpu-exclusive",
"--amgx-mpi-gpu-exclusive",
74 "Create MPI teams when using AmgX to load balance between ranks and GPUs.");
75 args.
AddOption(&device_config,
"-d",
"--device",
76 "Device configuration string, see Device::Configure().");
77 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
79 "Enable or disable GLVis visualization.");
80 args.
AddOption(&ndevices,
"-nd",
"--gpus-per-node-in-teams-mode",
81 "Number of GPU devices per node (Only used if amgx_mpi_teams is true).");
99 Device device(device_config);
100 if (myid == 0) { device.
Print(); }
105 Mesh mesh(mesh_file, 1, 1);
114 (int)floor(log(10000./mesh.
GetNE())/log(2.)/
dim);
115 for (
int l = 0; l < ref_levels; l++)
124 ParMesh pmesh(MPI_COMM_WORLD, mesh);
127 int par_ref_levels = 2;
128 for (
int l = 0; l < par_ref_levels; l++)
150 cout <<
"Using isoparametric FEs: " << fec->
Name() << endl;
162 cout <<
"Number of finite element unknowns: " << size << endl;
195 if (pa) {
a.SetAssemblyLevel(AssemblyLevel::PARTIAL); }
202 if (static_cond) {
a.EnableStaticCondensation(); }
207 a.FormLinearSystem(ess_tdof_list, x,
b, A, X, B);
230 else if (amgx_lib && strcmp(amgx_json_file,
"") == 0)
232 MFEM_VERIFY(!amgx_mpi_teams,
233 "Please add JSON file to try AmgX with MPI teams mode");
235 bool amgx_verbose =
false;
249 else if (amgx_lib && strcmp(amgx_json_file,
"") != 0)
293 ostringstream mesh_name, sol_name;
294 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << myid;
295 sol_name <<
"sol." << setfill(
'0') << setw(6) << myid;
297 ofstream mesh_ofs(mesh_name.str().c_str());
298 mesh_ofs.precision(8);
299 pmesh.
Print(mesh_ofs);
301 ofstream sol_ofs(sol_name.str().c_str());
302 sol_ofs.precision(8);
312 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
313 sol_sock.precision(8);
314 sol_sock <<
"solution\n" << pmesh << x << flush;
MFEM wrapper for Nvidia's multigrid library, AmgX (github.com/NVIDIA/AMGX)
@ EXTERNAL
Configure will be read from a specified file.
void Finalize()
Close down the AmgX library and free up any MPI Comms set up for it.
virtual void SetOperator(const Operator &op)
Sets the Operator that is going to be solved via AmgX. Supports operators based on either an MFEM Spa...
void SetConvergenceCheck(bool setConvergenceCheck_=true)
Add a check for convergence after applying Mult.
void InitMPITeams(const MPI_Comm &comm, const int nDevs)
Initialize the AmgX library and create MPI teams based on the number of devices on each node nDevs....
virtual void Mult(const Vector &b, Vector &x) const
Utilize the AmgX library to solve the linear system where the "matrix" is the AMG approximation to th...
void ReadParameters(const std::string config, CONFIG_SRC source)
Read in the AmgX parameters either through a file or directly through a properly formated string....
void InitExclusiveGPU(const MPI_Comm &comm)
Initialize the AmgX library in parallel mode with exactly one GPU per rank after the solver configura...
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
int Size() const
Return the logical size of the array.
Conjugate gradient method.
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
virtual void Mult(const Vector &b, Vector &x) const
Iterative solution of the linear system using the Conjugate Gradient method.
A coefficient that is constant across space and time.
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
Class for domain integration .
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
virtual const char * Name() const
Arbitrary order H1-conforming (continuous) finite elements.
The BoomerAMG solver in hypre.
Wrapper for hypre's ParCSR matrix class.
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
void SetRelTol(real_t rtol)
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
virtual void SetPrintLevel(int print_lvl)
Legacy method to set the level of verbosity of the solver output.
void SetMaxIter(int max_it)
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
void Clear()
Clear the contents of the Mesh.
int GetNE() const
Returns number of elements.
int Dimension() const
Dimension of the reference space used within the elements.
void GetNodes(Vector &node_coord) const
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
static int WorldRank()
Return the MPI rank in MPI_COMM_WORLD.
static int WorldSize()
Return the size of MPI_COMM_WORLD.
static void Init(int &argc, char **&argv, int required=default_thread_required, int *provided=nullptr)
Singleton creation with Mpi::Init(argc, argv).
Pointer to an Operator of a specified type.
OpType * As() const
Return the Operator pointer statically cast to a specified OpType. Similar to the method Get().
Jacobi smoothing for a given bilinear form (no matrix necessary).
virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x)
Reconstruct a solution vector x (e.g. a GridFunction) from the solution X of a constrained linear sys...
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintUsage(std::ostream &out) const
Print the usage message.
void PrintOptions(std::ostream &out) const
Print the options.
void AddOption(bool *var, const char *enable_short_name, const char *enable_long_name, const char *disable_short_name, const char *disable_long_name, const char *description, bool required=false)
Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool...
bool Good() const
Return true if the command line options were parsed successfully.
Abstract parallel finite element space.
void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1) const override
HYPRE_BigInt GlobalTrueVSize() const
Class for parallel grid function.
void Save(std::ostream &out) const override
Class for parallel meshes.
void Print(std::ostream &out=mfem::out, const std::string &comments="") const override
bool UsesTensorBasis(const FiniteElementSpace &fes)
Return true if the mesh contains only one topology and the elements are tensor elements.