Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-AMReX command line arguments are not cleanly passed through Initialize() #538

Closed
denera opened this issue Aug 3, 2019 · 2 comments
Closed

Comments

@denera
Copy link

denera commented Aug 3, 2019

@dwillcox and I have been working on the hands-on example for ATPESC when this issue cropped up. We have a PDE-constrained optimization problem (boundary control) with PETSc/TAO at the top driving the optimization and AMReX underneath doing the Poisson forward and adjoint solutions. Command line arguments we use for PETSc/TAO cause AMReX to crash on initialization because AMReX isn't just ignoring arguments it doesn't recognize. We've worked around the issue by hard-coding parameters we need for AMReX and initializing it without an inputs file so that PETSc/TAO is the only library that parses the arguments. However, in the long term interest of making AMReX play nicer with other libraries, Don and I thought it would be good to file an issue here.

@asalmgren
Copy link
Member

In this example, main.cpp starts with

int main (int argc, char* argv[])
{
amrex::Initialize(argc, argv);
.....
and so the whole command line is passed to AMReX. In the case where we only want AMReX to read the first argument (typically the name of the inputs file) and ignore everything past that (so that, for example, we can pass those arguments to PETSc/TAO instead), we can intercept the argc argument as below:

int main (int argc, char* argv[])
{
int argc_to_initialize = 2;
amrex::Initialize(argc_to_initialize, argv);
.....
which tells the AMReX code to only read the first two arguments (the first one being the name of the executable). So, for example, if we had the command line as follows:

main2d*.exe inputs -tao_monitor

then AMReX will parse the inputs file but will ignore the "-tao_monitor"

@WeiqunZhang
Copy link
Member

I made some changes to AMReX development branch. It will now ignore everything after -- surrounded by spaces. You should be able to do

./exe inputs amrex.x=0 amrex.y=1 amrex.z=2 foo=3 bar=4 -- -tao_monitor --tao_others

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants