Re: [netcdfgroup] NetCDF 4.0.1 with --enable-netcdf-4 conflicts with Open MPI by redefining MPI_Comm, etc

  • To: Ted Mansell <Ted.Mansell@xxxxxxxx>
  • Subject: Re: [netcdfgroup] NetCDF 4.0.1 with --enable-netcdf-4 conflicts with Open MPI by redefining MPI_Comm, etc
  • From: Constantine Khroulev <c.khroulev@xxxxxxxxx>
  • Date: Mon, 5 Oct 2009 13:34:31 -0800
Hello,

On Oct 5, 2009, at 12:38 PM, Ted Mansell wrote:

You can use non-MPI netcdf with an MPI program as long as you don't try to use parallel IO. At least it works for me with Fortran with the netcdf module ("USE NETCDF"). I guess you are using C?

I am using C++ and the NetCDF-C API.

Could there be an ifndef to check if MPI is in use before defining those vars in netcdf.h? Like:

#ifndef MPI_COMM_WORLD
#define MPI_Comm int
#define MPI_Info int
#define MPI_COMM_WORLD 0
#define MPI_INFO_NULL 0
#endif

And make sure that netcdf.h comes after mpi.h.

An alternative would be to turn off the create_par and open_par in the header and code.

Either solution would work just fine for me.

By the way: below is a completely benign piece of code that breaks because of redefined MPI_Comm et al:
===
#include <mpi.h>
#include <netcdf.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) {
  MPI_Comm comm = MPI_COMM_WORLD;
  int mpi_size, mpi_rank;

  /* Initialize MPI. */

  MPI_Init(&argc,&argv);
  MPI_Comm_size(comm, &mpi_size);
  MPI_Comm_rank(comm, &mpi_rank);

  for (int i = 0; i < mpi_size; i++) {
    if (i != mpi_rank) {
      MPI_Barrier(comm);
      continue;
    }

    printf("I am processor %d.\n", mpi_rank);
    MPI_Barrier(comm);
  }

  MPI_Finalize();

  return 0;
}
===

Note that it does not use NetCDF at all. I think #including a header should do no harm, generally...


On Oct 5, 2009, at 3:08 PM, Constantine Khroulev wrote:

Hello,

I have a problem: NetCDF 4.0.1 adds the following lines to netcdf.h (HDF5 is, in fact, built without parallel I/O support.):

===
/* These defs added by netCDF configure because parallel HDF5 is not present. */
#define MPI_Comm int
#define MPI_Info int
#define MPI_COMM_WORLD 0
#define MPI_INFO_NULL 0
===

This (it seems to me) makes it impossible to use MPI (or PETSc) with NetCDF, producing warnings like
===
/opt/local/include/netcdf.h:43:1: warning: "MPI_COMM_WORLD" redefined
In file included from /Users/constantine/Documents/PISM/petsc-3.0.0- p0/include/petsc.h:137, from /Users/constantine/Documents/PISM/petsc-3.0.0- p0/include/petscis.h:7, from /Users/constantine/Documents/PISM/petsc-3.0.0- p0/include/petscvec.h:9, from /Users/constantine/Documents/PISM/petsc-3.0.0- p0/include/petscda.h:7,
               from ../src/base/grid.cc:20:
===

and errors similar to
===
../src/base/grid.cc:64: error: invalid conversion from ‘int’ to ‘ompi_communicator_t*’
===





  • 2009 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: