Skip to content

Commit

Permalink
Fix libROM builds for OSX (#287)
Browse files Browse the repository at this point in the history
* Fix libROM builds for OSX

* Replaced MPI_Session with Mpi, corresponding to MFEM changes.

---------

Co-authored-by: dylan-copeland <[email protected]>
  • Loading branch information
ckendrick and dylan-copeland authored Jun 24, 2024
1 parent 99661b7 commit 48f21d5
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 95 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ if((CMAKE_BUILD_TYPE STREQUAL "Debug") OR
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()

if (CMAKE_HOST_APPLE)
# Fix linker flags for OSX to use classic linker on XCode 15.0+:
# https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Linking
set(MPI_Fortran_LINK_FLAGS "${MPI_Fortran_LINK_FLAGS} -Wl,-ld_classic")
endif()

set(CAROM_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(CAROM_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(CAROM_VERSION_PATCHLEVEL "${PROJECT_VERSION_PATCH}")
Expand Down
25 changes: 13 additions & 12 deletions examples/dmd/de_dg_advection_greedy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,8 @@ class FE_Evolution : public TimeDependentOperator
virtual ~FE_Evolution();
};

// 1. Initialize MPI.
MPI_Session mpi;
int num_procs = mpi.WorldSize();
int myid = mpi.WorldRank();
//MFEM variables
int num_procs, myid;
const char *mesh_file = "../data/periodic-hexagon.mesh";
int ser_ref_levels = 2;
int par_ref_levels = 0;
Expand Down Expand Up @@ -367,7 +364,7 @@ double simulation()
ode_solver = new SDIRK34Solver;
break;
default:
if (mpi.Root())
if (myid == 0)
{
cout << "Unknown ODE solver type: " << ode_solver_type << '\n';
}
Expand Down Expand Up @@ -405,7 +402,7 @@ double simulation()
ParFiniteElementSpace *fes = new ParFiniteElementSpace(pmesh, &fec);

HYPRE_BigInt global_vSize = fes->GlobalTrueVSize();
if (mpi.Root())
if (myid == 0)
{
cout << "Number of unknowns: " << global_vSize << endl;
}
Expand Down Expand Up @@ -549,11 +546,11 @@ double simulation()
sout.open(vishost, visport);
if (!sout)
{
if (mpi.Root())
if (myid == 0)
cout << "Unable to connect to GLVis server at "
<< vishost << ':' << visport << endl;
visualization = false;
if (mpi.Root())
if (myid == 0)
{
cout << "GLVis visualization disabled.\n";
}
Expand Down Expand Up @@ -790,7 +787,7 @@ double simulation()

if (done || ti % vis_steps == 0)
{
if (mpi.Root())
if (myid == 0)
{
cout << "time step: " << ti << ", time: " << t << endl;
}
Expand Down Expand Up @@ -1141,6 +1138,10 @@ class RelativeDifferenceCostFunction : public CAROM::IOptimizable

int main(int argc, char *argv[])
{
// 1. Initialize MPI.
mfem::Mpi::Init();
num_procs = Mpi::WorldSize();
myid = Mpi::WorldRank();

cout.precision(precision);
// 2. Parse command-line options.
Expand Down Expand Up @@ -1251,19 +1252,19 @@ int main(int argc, char *argv[])
args.Parse();
if (!args.Good())
{
if (mpi.Root())
if (myid == 0)
{
args.PrintUsage(cout);
}
return 1;
}
if (mpi.Root())
if (myid == 0)
{
args.PrintOptions(cout);
}

Device device(device_config);
if (mpi.Root()) {
if (myid == 0) {
device.Print();
}

Expand Down
22 changes: 11 additions & 11 deletions examples/dmd/dg_advection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ class FE_Evolution : public TimeDependentOperator
int main(int argc, char *argv[])
{
// 1. Initialize MPI.
MPI_Session mpi;
int num_procs = mpi.WorldSize();
int myid = mpi.WorldRank();
Mpi::Init();
const int num_procs = Mpi::WorldSize();
const int myid = Mpi::WorldRank();

// 2. Parse command-line options.
problem = 0;
Expand Down Expand Up @@ -322,19 +322,19 @@ int main(int argc, char *argv[])
args.Parse();
if (!args.Good())
{
if (mpi.Root())
if (myid == 0)
{
args.PrintUsage(cout);
}
return 1;
}
if (mpi.Root())
if (myid == 0)
{
args.PrintOptions(cout);
}

Device device(device_config);
if (mpi.Root()) {
if (myid == 0) {
device.Print();
}

Expand Down Expand Up @@ -385,7 +385,7 @@ int main(int argc, char *argv[])
ode_solver = new SDIRK34Solver;
break;
default:
if (mpi.Root())
if (myid == 0)
{
cout << "Unknown ODE solver type: " << ode_solver_type << '\n';
}
Expand Down Expand Up @@ -423,7 +423,7 @@ int main(int argc, char *argv[])
ParFiniteElementSpace *fes = new ParFiniteElementSpace(pmesh, &fec);

HYPRE_BigInt global_vSize = fes->GlobalTrueVSize();
if (mpi.Root())
if (myid == 0)
{
cout << "Number of unknowns: " << global_vSize << endl;
}
Expand Down Expand Up @@ -563,11 +563,11 @@ int main(int argc, char *argv[])
sout.open(vishost, visport);
if (!sout)
{
if (mpi.Root())
if (myid == 0)
cout << "Unable to connect to GLVis server at "
<< vishost << ':' << visport << endl;
visualization = false;
if (mpi.Root())
if (myid == 0)
{
cout << "GLVis visualization disabled.\n";
}
Expand Down Expand Up @@ -628,7 +628,7 @@ int main(int argc, char *argv[])

if (done || ti % vis_steps == 0)
{
if (mpi.Root())
if (myid == 0)
{
cout << "time step: " << ti << ", time: " << t << endl;
}
Expand Down
42 changes: 22 additions & 20 deletions examples/dmd/dg_euler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ double max_char_speed;
int main(int argc, char *argv[])
{
// 1. Initialize MPI.
MPI_Session mpi(argc, argv);
Mpi::Init();
const int num_procs = Mpi::WorldSize();
const int myid = Mpi::WorldRank();

// 2. Parse command-line options.
problem = 1;
Expand Down Expand Up @@ -197,12 +199,12 @@ int main(int argc, char *argv[])
args.Parse();
if (!args.Good())
{
if (mpi.Root()) {
if (myid == 0) {
args.PrintUsage(cout);
}
return 1;
}
if (mpi.Root()) {
if (myid == 0) {
args.PrintOptions(cout);
}

Expand Down Expand Up @@ -234,7 +236,7 @@ int main(int argc, char *argv[])
ode_solver = new RK6Solver;
break;
default:
if (mpi.Root())
if (myid == 0)
{
cout << "Unknown ODE solver type: " << ode_solver_type << '\n';
}
Expand Down Expand Up @@ -273,7 +275,7 @@ int main(int argc, char *argv[])
MFEM_ASSERT(fes.GetOrdering() == Ordering::byNODES, "");

HYPRE_BigInt glob_size = vfes.GlobalTrueVSize();
if (mpi.Root()) {
if (myid == 0) {
cout << "Number of unknowns: " << glob_size << endl;
}

Expand All @@ -299,7 +301,7 @@ int main(int argc, char *argv[])
// Output the initial solution.
{
ostringstream mesh_name;
mesh_name << "vortex-mesh." << setfill('0') << setw(6) << mpi.WorldRank();
mesh_name << "vortex-mesh." << setfill('0') << setw(6) << myid;
ofstream mesh_ofs(mesh_name.str().c_str());
mesh_ofs.precision(precision);
mesh_ofs << pmesh;
Expand All @@ -309,7 +311,7 @@ int main(int argc, char *argv[])
ParGridFunction uk(&fes, u_block.GetBlock(k));
ostringstream sol_name;
sol_name << "vortex-" << k << "-init."
<< setfill('0') << setw(6) << mpi.WorldRank();
<< setfill('0') << setw(6) << myid;
ofstream sol_ofs(sol_name.str().c_str());
sol_ofs.precision(precision);
sol_ofs << uk;
Expand Down Expand Up @@ -342,19 +344,19 @@ int main(int argc, char *argv[])
sout.open(vishost, visport);
if (!sout)
{
if (mpi.Root())
if (myid == 0)
{
cout << "Unable to connect to GLVis server at "
<< vishost << ':' << visport << endl;
}
visualization = false;
if (mpi.Root()) {
if (myid == 0) {
cout << "GLVis visualization disabled.\n";
}
}
else
{
sout << "parallel " << mpi.WorldSize() << " " << mpi.WorldRank() << "\n";
sout << "parallel " << num_procs << " " << myid << "\n";
sout.precision(precision);
sout << "solution\n" << pmesh << mom;
sout << flush;
Expand Down Expand Up @@ -486,14 +488,14 @@ int main(int argc, char *argv[])

if (done || ti % vis_steps == 0)
{
if (mpi.Root())
if (myid == 0)
{
cout << "time step: " << ti << ", time: " << t << endl;
}
if (visualization)
{
MPI_Barrier(pmesh.GetComm());
sout << "parallel " << mpi.WorldSize() << " " << mpi.WorldRank() << "\n";
sout << "parallel " << num_procs << " " << myid << "\n";
sout << "solution\n" << pmesh << mom << flush;
}
if (visit)
Expand All @@ -506,7 +508,7 @@ int main(int argc, char *argv[])
}

tic_toc.Stop();
if (mpi.Root()) {
if (myid == 0) {
cout << " done, " << tic_toc.RealTime() << "s." << endl;
}

Expand All @@ -517,7 +519,7 @@ int main(int argc, char *argv[])
ParGridFunction uk(&fes, u_block.GetBlock(k));
ostringstream sol_name;
sol_name << "vortex-" << k << "-final."
<< setfill('0') << setw(6) << mpi.WorldRank();
<< setfill('0') << setw(6) << myid;
ofstream sol_ofs(sol_name.str().c_str());
sol_ofs.precision(precision);
sol_ofs << uk;
Expand All @@ -527,13 +529,13 @@ int main(int argc, char *argv[])
if (t_final == 2.0)
{
const double error = sol.ComputeLpError(2, u0);
if (mpi.Root()) {
if (myid == 0) {
cout << "Solution error: " << error << endl;
}
}

// 13. Calculate the DMD modes.
if (mpi.WorldRank() == 0 && rdim != -1 && ef != -1)
if (myid == 0 && rdim != -1 && ef != -1)
{
std::cout << "Both rdim and ef are set. ef will be ignored." << std::endl;
}
Expand All @@ -542,7 +544,7 @@ int main(int argc, char *argv[])

if (rdim != -1)
{
if (mpi.WorldRank() == 0)
if (myid == 0)
{
std::cout << "Creating DMD with rdim: " << rdim << std::endl;
}
Expand All @@ -553,7 +555,7 @@ int main(int argc, char *argv[])
}
else if (ef != -1)
{
if (mpi.WorldRank() == 0)
if (myid == 0)
{
std::cout << "Creating DMD with energy fraction: " << ef << std::endl;
}
Expand All @@ -575,7 +577,7 @@ int main(int argc, char *argv[])
true_solution_e = u_block.GetBlock(3).GetData();

// 14. Predict using DMD.
if (mpi.WorldRank() == 0)
if (myid == 0)
{
std::cout << "Predicting density, momentum, and energy using DMD" << std::endl;
}
Expand Down Expand Up @@ -680,7 +682,7 @@ int main(int argc, char *argv[])
double tot_true_solution_e_norm = sqrt(InnerProduct(MPI_COMM_WORLD,
true_solution_e, true_solution_e));

if (mpi.WorldRank() == 0)
if (myid == 0)
{
std::cout << "Relative error of DMD density (dens) at t_final: " << t_final <<
" is " << tot_diff_norm_dens / tot_true_solution_dens_norm << std::endl;
Expand Down
12 changes: 6 additions & 6 deletions examples/dmd/local_dw_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ int main(int argc, char *argv[])
cout.precision(precision);

// 1. Initialize MPI.
MPI_Session mpi;
int num_procs = mpi.WorldSize();
int myid = mpi.WorldRank();
Mpi::Init();
const int num_procs = Mpi::WorldSize();
const int myid = Mpi::WorldRank();

// 2. Parse command-line options.
bool train = true;
Expand Down Expand Up @@ -141,13 +141,13 @@ int main(int argc, char *argv[])
args.Parse();
if (!args.Good())
{
if (mpi.Root())
if (myid == 0)
{
args.PrintUsage(cout);
}
return 1;
}
if (mpi.Root())
if (myid == 0)
{
args.PrintOptions(cout);
}
Expand All @@ -166,7 +166,7 @@ int main(int argc, char *argv[])
outputPath += "/" + string(basename);
}

if (mpi.Root()) {
if (myid == 0) {
const char path_delim = '/';
string::size_type pos = 0;
do {
Expand Down
Loading

0 comments on commit 48f21d5

Please sign in to comment.