Skip to content

Cannot build AMReX 20.11 with PETSc (?) #3009

@eschnett

Description

@eschnett

I see this build error:

COMPILING CarpetX/PDESolvers/src/solve.cxx
In file included from /Users/eschnett/Cactus/view/include/AMReX_FabArrayBase.H:8,
                 from /Users/eschnett/Cactus/view/include/AMReX_MFIter.H:5,
                 from /Users/eschnett/Cactus/view/include/AMReX_Reduce.H:8,
                 from /Users/eschnett/Cactus/view/include/AMReX_BaseFab.H:20,
                 from /Users/eschnett/Cactus/view/include/AMReX_FArrayBox.H:7,
                 from /Users/eschnett/Cactus/arrangements/CarpetX/Loop/src/loop.hxx:4,
                 from /Users/eschnett/Cactus/configs/sim-debug/bindings/include/loop.hxx:4,
                 from /Users/eschnett/Cactus/arrangements/CarpetX/PDESolvers/src/../../CarpetX/src/driver.hxx:4,
                 from /Users/eschnett/Cactus/arrangements/CarpetX/PDESolvers/src/solve.cxx:4:
/Users/eschnett/Cactus/view/include/AMReX_ParallelReduce.H:131:78: error: macro "MPI_Allreduce" passed 7 arguments, but takes just 6
  131 |                       ParallelDescriptor::Mpi_op<T,amrex::Greater<T>>(), comm);
      |                                                                              ^

The complete statement in this line is

        MPI_Allreduce(&tmp, &vi, 1,
                      ParallelDescriptor::Mpi_typemap<T>::type(),
                      ParallelDescriptor::Mpi_op<T,amrex::Greater<T>>(), comm);

Clearly, this function call has 6 arguments, as it should.

I think the problem is the following. The caller uses PETSc, and includes various PETSc include files as well. PETSc contains this line

    #define MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, comm) (petsc_allreduce_ct += PetscMPIParallelComm((comm)), MPI_Allreduce((sendbuf), (recvbuf), (count), (datatype), (op), (comm)))

in its header file petsclog.h. This turns MPI_Allreduce into a macro (sneaky!), and the C++ preprocessor is then getting confused by the comma in the template argument to Mpi_op.

Obviously, PETSc should not be doing this. In the spirit of defensive programming, do you nonetheless want to add parentheses around this argument, as in (ParallelDescriptor::Mpi_op<T,amrex::Greater<T>>())?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions