35 #error This example requires that MFEM is built with MFEM_USE_AMGX=YES
38 int main(
int argc,
char *argv[])
41 Mpi::Init(argc, argv);
42 int num_procs = Mpi::WorldSize();
43 int myid = Mpi::WorldRank();
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;
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;
236 prec =
new AmgXSolver(MPI_COMM_WORLD, AmgXSolver::PRECONDITIONER,
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;
int Size() const
Return the logical size of the array.
Class for domain integration L(v) := (f, v)
virtual void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1)
Conjugate gradient method.
OpType * As() const
Return the Operator pointer statically cast to a specified OpType. Similar to the method Get()...
A coefficient that is constant across space and time.
virtual void Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
Pointer to an Operator of a specified type.
HYPRE_BigInt GlobalTrueVSize() const
int GetNE() const
Returns number of elements.
virtual void Save(std::ostream &out) const
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
Abstract parallel finite element space.
void InitMPITeams(const MPI_Comm &comm, const int nDevs)
bool UsesTensorBasis(const FiniteElementSpace &fes)
Return true if the mesh contains only one topology and the elements are tensor elements.
void ReadParameters(const std::string config, CONFIG_SRC source)
virtual void Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
The BoomerAMG solver in hypre.
void SetConvergenceCheck(bool setConvergenceCheck_=true)
Add a check for convergence after applying Mult.
virtual void SetPrintLevel(int print_lvl)
Legacy method to set the level of verbosity of the solver output.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
Jacobi smoothing for a given bilinear form (no matrix necessary).
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
void SetMaxIter(int max_it)
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void PrintUsage(std::ostream &out) const
Print the usage message.
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
void SetRelTol(double rtol)
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
virtual void SetOperator(const Operator &op)
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...
virtual const char * Name() const
void InitExclusiveGPU(const MPI_Comm &comm)
void PrintOptions(std::ostream &out) const
Print the options.
void Clear()
Clear the contents of the Mesh.
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
void GetNodes(Vector &node_coord) const
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
Arbitrary order H1-conforming (continuous) finite elements.
void Print(std::ostream &out=mfem::out) const override
Class for parallel grid function.
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
Wrapper for hypre's ParCSR matrix class.
Class for parallel meshes.
bool Good() const
Return true if the command line options were parsed successfully.