Skip to content

Commit

Permalink
Redo the CMake examples; add Ioss example
Browse files Browse the repository at this point in the history
  • Loading branch information
gsjaardema committed Apr 5, 2024
1 parent 9e352f4 commit 5559f92
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 20 deletions.
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,25 @@ add_executable(ExodusReadFor ExodusRead.f)
target_link_libraries(ExodusReadFor PRIVATE SEACASExodus_for::all_libs)
```

The `cmake-use-example` directory contains this sample
`CMakeLists.txt` file and a couple C and Fortran files which provide
an example of how to build and link a C or Fortran program with the
Exodus library installed as part of a build of this package.
A similar CMakeLists.txt file for using the IOSS library would be something like:

```sh
cmake_minimum_required(VERSION 3.1...3.26)
project(IossCMakeExample VERSION 1.0 LANGUAGES CXX)

#### C++ IOSS ####
find_package(SEACASIoss CONFIG)
add_executable(IossExample IossExample.C)
target_link_libraries(IossExample PRIVATE SEACASIoss::all_libs)
```

The `cmake-use-example` directory contains Exodus example files in the
`exodus` subdirectory and Ioss example files in the `ioss` subdirectory.
These provide short examples of how to build and link a program with the
Exodus and/or Ioss libraries.

To use this, copy the contents of the directory to your own filespace
and modify the contents as needed. The example provides a C
executable and a Fortran Executable which both are linked to the
Exodus library.
and modify the contents as needed.

To configure and build, you would do something like:

Expand All @@ -247,19 +257,10 @@ To configure and build, you would do something like:
CMAKE_PREFIX_PATH={path_to_root_of_seacas_install} cmake ..
make
```
And you would then get `ExodusWriteC` and `ExodusReadFor` compiled and linked against the Exodus library.

A similar CMakeLists.txt file for using the IOSS library would be something like:

```sh
cmake_minimum_required(VERSION 3.1...3.26)
project(IOSSCMakeExample VERSION 1.0 LANGUAGES CXX)

#### C++ IOSS CMake Example ####
find_package(SEACASIoss CONFIG)
add_executable(ioss_exe ioss_exe.C)
target_link_libraries(ioss_exe PRIVATE SEACASIoss::all_libs)
```
And you would then get an executable (`ExodusWriteC` and
`ExodusReadFor` for Exodus, `IossExample` for Ioss) compiled and linked
against the Exodus and/or Ioss libraries.

## Required Software

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ add_executable(ExodusWriteC ExodusWrite.c)
target_link_libraries(ExodusWriteC PRIVATE SEACASExodus::all_libs)


#### FORTRAN #####
#### FORTRAN ##### (Remove all below if only using Exodus C API)
IF ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fcray-pointer -fdefault-real-8 -fdefault-integer-8 -fno-range-check")
ELSEIF ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "XL")
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions cmake-use-example/ioss/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1...3.26)
project(IossCMakeExample VERSION 1.0 LANGUAGES CXX)

#### C++ IOSS ####
find_package(SEACASIoss CONFIG)
add_executable(IossExample IossExample.C)
target_link_libraries(IossExample PRIVATE SEACASIoss::all_libs)
43 changes: 43 additions & 0 deletions cmake-use-example/ioss/IossExample.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <Ionit_Initializer.h>
#include <Ioss_DatabaseIO.h>
#include <Ioss_IOFactory.h>
#include <Ioss_Region.h>
#include <Ioss_Utils.h>

#include <assert.h>
#include <iostream>
#include <string>

int main(int argc, char *argv[]) {
#ifdef SEACAS_HAVE_MPI
MPI_Init(&argc, &argv);
ON_BLOCK_EXIT(MPI_Finalize);
#endif

if (argc == 1) {
std::cerr << "SYNTAX: " << argv[0]
<< " '--show-config' or 'filename'\n"
" Will either show the Ioss build configuration\n"
" Or will show a summary of the data in `filename`\n";
std::exit(EXIT_SUCCESS);
}

Ioss::Init::Initializer io;
std::string filename = argv[1];
if (filename == "--show-config") {
std::cerr << Ioss::IOFactory::show_configuration() << "\n";
} else {
auto dbtype = Ioss::Utils::get_type_from_file(filename);
auto *dbi = Ioss::IOFactory::create(dbtype, filename, Ioss::READ_RESTART,
Ioss::ParallelUtils::comm_world());

if (dbi == NULL || !dbi->ok(true)) {
std::exit(EXIT_FAILURE);
}

// NOTE: 'region' owns 'dbi' pointer at this time and will close
// and call dbi destructor.
Ioss::Region region(dbi, "example_region");
region.output_summary(std::cerr);
}
}

0 comments on commit 5559f92

Please sign in to comment.