Skip to content

Commit

Permalink
Merge pull request #166 from PrincetonUniversity/issue-155
Browse files Browse the repository at this point in the history
Fix for Apple clang compilation
  • Loading branch information
lsawade authored Nov 25, 2024
2 parents 78365e2 + e9f583b commit f9e28df
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 23 deletions.
16 changes: 8 additions & 8 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Description

Please describe the changes/features in this pull request.
Please describe the changes/features in this pull request.

# Issue Number

If there is an issue created for these changes, link it here

# Checklist

Please make sure to check developer documentation on specfem docs.
Please make sure to check developer documentation on specfem docs.

[] I ran the code through pre-commit to check style
[] My code passes all the integration tests
[] I have added sufficient unittests to test my changes
[] I have added/updated documentation for the changes I am proposing
[] I have updated CMakeLists to ensure my code builds
[] My code builds across all platforms
- [ ] I ran the code through pre-commit to check style
- [ ] My code passes all the integration tests
- [ ] I have added sufficient unittests to test my changes
- [ ] I have added/updated documentation for the changes I am proposing
- [ ] I have updated CMakeLists to ensure my code builds
- [ ] My code builds across all platforms
5 changes: 5 additions & 0 deletions docs/getting_started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ The following table lists the versions of compilers that are supported by SPECFE
* Not Tested
* 8.0.0, latest

* * Apple Clang
* 16.0.0 (MacOS Sequoia)
* Not Tested
* 8.0.0, latest

* * NVC++
* Not Tested
* Not Tested
Expand Down
8 changes: 4 additions & 4 deletions include/IO/ASCII/impl/datasetbase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ template <> class DatasetBase<specfem::IO::write> {
boost::filesystem::remove(metadata_path);
}

std::ofstream metadata(metadata_path);
std::ofstream metadata(metadata_path.string());
if (!metadata.is_open()) {
std::ostringstream oss;
oss << "ERROR : Could not open file " << metadata_path;
Expand All @@ -55,7 +55,7 @@ template <> class DatasetBase<specfem::IO::write> {

template <typename value_type> void write(const value_type *data) const {

std::ofstream file(file_path);
std::ofstream file(file_path.string());
if (!file.is_open()) {
std::ostringstream oss;
oss << "ERROR : Could not open file " << file_path;
Expand Down Expand Up @@ -97,7 +97,7 @@ template <> class DatasetBase<specfem::IO::read> {
oss << "ERROR : Metadata file " << metadata_path << " does not exist";
throw std::runtime_error(oss.str());
}
std::ifstream metadata(metadata_path);
std::ifstream metadata(metadata_path.string());
if (!metadata.is_open()) {
std::ostringstream oss;
oss << "ERROR : Could not open file " << metadata_path;
Expand Down Expand Up @@ -143,7 +143,7 @@ template <> class DatasetBase<specfem::IO::read> {
}

template <typename value_type> void read(value_type *data) const {
std::ifstream file(file_path);
std::ifstream file(file_path.string());
if (!file.is_open()) {
std::ostringstream oss;
oss << "ERROR : Could not open file " << file_path;
Expand Down
4 changes: 2 additions & 2 deletions include/parameter_parser/setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class setup {
/**
* @brief Log the header and description of the simulation
*/
std::string print_header(
const std::chrono::time_point<std::chrono::high_resolution_clock> now);
std::string
print_header(const std::chrono::time_point<std::chrono::system_clock> now);

/**
* @brief Get delta time value
Expand Down
38 changes: 38 additions & 0 deletions meshfem2d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,46 @@ unset(WITH_SCOTCH)
enable_language(Fortran)
enable_language(C)

# Set the C compiler
set(FCFLAGS_f90 -g -O2 -fbacktrace)

# Check if CFLAGS is defined
if (DEFINED ENV{CFLAGS})
set(CFLAGS "$ENV{CFLAGS}")
endif()

message("-- CFLAGS: ${CFLAGS}")

# Check if MacOS
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
message("-- macOS detected")
endif()

# Check if Clang
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CLANG TRUE)
message("-- Detected usage of clang on macOS")
endif()

# Fix for macos and clang include files... sometimes I hate mac.
if (MACOSX AND CLANG)
message("-- Fixing include files for macOS and Clang")
set (FCFLAGS_f90 "${FCFLAGS_f90}")
# In the future, we can use the following line to add the flags to the compiler
# add_compile_options($<$<COMPILE_LANGUAGE:C>:-isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk>)
# set (CFLAGS "${CFLAGS})
# Right now we can use the following line to add the flags to the compiler
if (DEFINED CFLAGS)
set(CFLAGS "$ENV{CFLAGS} -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk")
else()
set(CFLAGS "-isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk")
endif()
endif()

message("-- CFLAGS: ${CFLAGS}")


## ========= MACROS =========
# define macro wrapper on custom command
macro(build_fortran_command module_name dependecies)
Expand Down
2 changes: 1 addition & 1 deletion src/parameter_parser/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ specfem::runtime_configuration::setup::setup(const std::string &parameter_file,
}

std::string specfem::runtime_configuration::setup::print_header(
const std::chrono::time_point<std::chrono::high_resolution_clock> now) {
const std::chrono::time_point<std::chrono::system_clock> now) {

std::ostringstream message;

Expand Down
16 changes: 8 additions & 8 deletions src/specfem2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
#include <vector>
// Specfem2d driver

std::string print_end_message(
std::chrono::time_point<std::chrono::high_resolution_clock> start_time,
std::chrono::duration<double> solver_time) {
std::string
print_end_message(std::chrono::time_point<std::chrono::system_clock> start_time,
std::chrono::duration<double> solver_time) {
std::ostringstream message;
// current date/time based on current system
const auto now = std::chrono::high_resolution_clock::now();
const auto now = std::chrono::system_clock::now();

std::time_t c_now = std::chrono::high_resolution_clock::to_time_t(now);
std::time_t c_now = std::chrono::system_clock::to_time_t(now);

std::chrono::duration<double> diff = now - start_time;

Expand Down Expand Up @@ -87,7 +87,7 @@ void execute(const std::string &parameter_file, const std::string &default_file,
// --------------------------------------------------------------
// Read parameter file
// --------------------------------------------------------------
auto start_time = std::chrono::high_resolution_clock::now();
auto start_time = std::chrono::system_clock::now();
specfem::runtime_configuration::setup setup(parameter_file, default_file);
const auto [database_filename, source_filename] = setup.get_databases();
mpi->cout(setup.print_header(start_time));
Expand Down Expand Up @@ -190,9 +190,9 @@ void execute(const std::string &parameter_file, const std::string &default_file,
mpi->cout("Executing time loop:");
mpi->cout("-------------------------------");

const auto solver_start_time = std::chrono::high_resolution_clock::now();
const auto solver_start_time = std::chrono::system_clock::now();
solver->run();
const auto solver_end_time = std::chrono::high_resolution_clock::now();
const auto solver_end_time = std::chrono::system_clock::now();

std::chrono::duration<double> solver_time =
solver_end_time - solver_start_time;
Expand Down

0 comments on commit f9e28df

Please sign in to comment.