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

Feature/netcdf mpi #43

Merged
merged 8 commits into from
Sep 3, 2020
Merged

Feature/netcdf mpi #43

merged 8 commits into from
Sep 3, 2020

Conversation

kgerheiser
Copy link
Contributor

@kgerheiser kgerheiser commented Sep 1, 2020

Find and link to MPI when NetCDF parallel is detected. Otherwise, user has to do it manually.

See: NOAA-EMC/wgrib2#15

Also, affects UFS_UTILS and anything else that links to NetCDF.

Tested on Jet and Orion

Modules/FindNetCDF.cmake Outdated Show resolved Hide resolved
@@ -231,6 +243,10 @@ foreach( _comp IN LISTS _search_components )
if( NOT _comp MATCHES "^(C)$" )
target_link_libraries(NetCDF::NetCDF_${_comp} INTERFACE NetCDF::NetCDF_C)
endif()
if(NetCDF_PARALLEL)
find_package(MPI REQUIRED COMPONENTS ${_comp})
target_link_libraries(NetCDF::NetCDF_${_comp} INTERFACE MPI::MPI_${_comp})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is appropriate in FindNetCDF.cmake.
I think the application using NetCDF should be responsible for linking with the MPI library.
e.g.
in wgrib2 or any other application e.g. chgres_cube, one could do one of two things:

  1. in the application CMakeLists.txt
if(NetCDF_PARALLEL)
  find_package(MPI REQUIRED COMPONENTS C)
  target_link_libraries(app/lib INTERFACE|PUBLIC|PRIVATE MPI::MPI_C)
endif()

I think only the C library is required, but I will have to test that.

  1. explicitly set CC and FC with the MPI wrapper e.g.
export CC=mpiicc
export FC=mpiifort

etc. or whatever the compiler is instead of e.g. CC=icc, FC=ifort

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really against either of those. In general, find_package links in its dependencies, but I could see it being different for MPI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a serial (non-MPI) application depends on (parallel) netcdf library, it will be much simpler to not need to add if(NetCDF_PARALLEL) .... endif() logic in application's CMakeLists.txt or require CC/FC to point to mpi wrapper scripts. Such program should not need to know anything about internal implementation/dependencies of netcdf.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @DusanJovic-NOAA and @kgerheiser that if netCDF depends on MPI, it needs to automatically configure the MPI dependencies for the application that it is used in.

Copy link
Collaborator

@aerorahul aerorahul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments.

@@ -171,6 +171,19 @@ function(netcdf_config exec flag output_var)
endif()
endfunction()


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the additional empty line?

@@ -231,6 +244,9 @@ foreach( _comp IN LISTS _search_components )
if( NOT _comp MATCHES "^(C)$" )
target_link_libraries(NetCDF::NetCDF_${_comp} INTERFACE NetCDF::NetCDF_C)
endif()
if(NetCDF_PARALLEL)
target_link_libraries(NetCDF::NetCDF_${_comp} INTERFACE MPI::MPI_C)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need indent here.
Also, why does the NetCDF_Fortran library need to interface with the MPI_C library?
This should be done before this for-loop and only for the NetCDF_C library. All other components automatically add NetCDF_C to their interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Admittedly, I didn't really know what INTERFACE was doing.

You can't do that before the for-loop. The library is created a couple lines above.

@kgerheiser
Copy link
Contributor Author

How about now?

Comment on lines 246 to 248
if(NetCDF_PARALLEL)
target_link_libraries(NetCDF::NetCDF_${_comp} INTERFACE MPI::MPI_C)
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_comp is C in this else block. Making it explicit doesn't change the result, just makes reading easy-er.
Is an indent missing? Or is this a tab issue?
Otherwise looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it explicit.

I don't know why it shows like that. See how it looks from here

https://github.com/kgerheiser/CMakeModules/blob/b636f83f5a1a9e98417c162b6ce60291d4d11488/Modules/FindNetCDF.cmake#L248

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you checkout your branch, the indentation is bonkers. See attached screen shot.
Also, get rid of trailing blanks on Line 181.
Screen Shot 2020-09-02 at 12 51 59 PM

You are using tabs and I think the tab-expansion in your editor is turned off or messed up.

@kgerheiser
Copy link
Contributor Author

I think it's actually fixed now

@kgerheiser kgerheiser merged commit 7fe17de into NOAA-EMC:develop Sep 3, 2020
@kgerheiser kgerheiser deleted the feature/netcdf-mpi branch September 3, 2020 15:37
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

Successfully merging this pull request may close these issues.

4 participants