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

File system compatibility #210

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/source/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ The compilation stops while compiling Kokkos with ``/usr/include/stdlib.h(58): e
When using the Intel compiler on a Mac Intel, I get a linking error involving the ``SharedAllocationRecordIvvE18t_tracking_enabledE`` symbol.
This is a known bug of the Intel Mac compiler with Kokkos. Apparently Intel has decided not to fix it. Check the issue on the `Kokkos git page <https://github.com/kokkos/kokkos/issues/1959>`_.

I get an error during *Idefix* link that says there are undefined symbols to std::filesystem
This is a known bug/limitation of the stdlibc++ provided with gcc8 that does not include C++17 filesystem extensions.
While *Idefix* auto-detects gcc8 when it is used as the main compiler, it still misses the cases when another compiler
(like Clang or Intel) is used with gcc8 as a backend.
You should try to clear up CMakeCache.txt and explicitely add the required link library when calling cmake as in
``LDFLAGS=-lstdc++fs cmake $IDEFIX_DIR ...```

Execution
---------

Expand Down
32 changes: 20 additions & 12 deletions src/output/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
// ***********************************************************************************

#include <unordered_set>
#include <filesystem>
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
error "Missing the <filesystem> header."
#endif
#include <iomanip>
#include "dump.hpp"
#include "version.hpp"
Expand Down Expand Up @@ -63,9 +71,9 @@ void Dump::Init(DataBlock *datain) {
this->dumpFileNumber = 0;

if(idfx::prank==0) {
if(!std::filesystem::is_directory(outputDirectory)) {
if(!fs::is_directory(outputDirectory)) {
try {
if(!std::filesystem::create_directory(outputDirectory)) {
if(!fs::create_directory(outputDirectory)) {
std::stringstream msg;
msg << "Cannot create directory " << outputDirectory << std::endl;
IDEFIX_ERROR(msg);
Expand Down Expand Up @@ -524,7 +532,7 @@ void Dump::ReadDistributed(IdfxFileHandler fileHdl, int ndim, int *dim, int *gdi
// Helper function to convert filesystem::file_time into std::time_t
// see https://stackoverflow.com/questions/56788745/
// This conversion "hack" is required in C++17 as no proper conversion bewteen
// std::filesystem::last_write_time and std::time_t
// fs::last_write_time and std::time_t
// exists in the standard library until C++20
template <typename TP>
std::time_t to_time_t(TP tp) {
Expand All @@ -533,15 +541,15 @@ std::time_t to_time_t(TP tp) {
return std::chrono::system_clock::to_time_t(sctp);
}

int Dump::GetLastDumpInDirectory(std::filesystem::path &directory) {
int Dump::GetLastDumpInDirectory(fs::path &directory) {
int num = -1;

std::time_t youngFileTime;
bool first = true;
for (const auto & entry : std::filesystem::directory_iterator(directory)) {
for (const auto & entry : fs::directory_iterator(directory)) {
// Check file extension
if(entry.path().extension().string().compare(".dmp")==0) {
auto fileTime = to_time_t(std::filesystem::last_write_time(entry.path()));
auto fileTime = to_time_t(fs::last_write_time(entry.path()));
// Check which one is the most recent
if(first || fileTime>youngFileTime) {
// std::tm *gmt = std::gmtime(&fileTime);
Expand All @@ -563,7 +571,7 @@ int Dump::GetLastDumpInDirectory(std::filesystem::path &directory) {
return(num);
}
bool Dump::Read(Output& output, int readNumber ) {
std::filesystem::path filename;
fs::path filename;
int nx[3];
int nxglob[3];
std::string fieldName;
Expand All @@ -574,7 +582,7 @@ bool Dump::Read(Output& output, int readNumber ) {

idfx::pushRegion("Dump::Read");

std::filesystem::path readDir = this->outputDirectory;
fs::path readDir = this->outputDirectory;

if(readNumber<0) {
// We actually don't know which file we're supposed to read, so let's guess
Expand Down Expand Up @@ -746,7 +754,7 @@ bool Dump::Read(Output& output, int readNumber ) {


int Dump::Write(Output& output) {
std::filesystem::path filename;
fs::path filename;
char fieldName[NAMESIZE+1]; // +1 is just in case
int nx[3];
int nxtot[3];
Expand Down Expand Up @@ -776,8 +784,8 @@ int Dump::Write(Output& output) {

// Check if file exists, if yes, delete it
if(idfx::prank==0) {
if(std::filesystem::exists(filename)) {
std::filesystem::remove(filename);
if(fs::exists(filename)) {
fs::remove(filename);
}
}

Expand Down
15 changes: 11 additions & 4 deletions src/output/dump.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
#define OUTPUT_DUMP_HPP_
#include <string>
#include <map>
#include <filesystem>

#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
error "Missing the <filesystem> header."
#endif
#include "idefix.hpp"
#include "input.hpp"
#include "dataBlock.hpp"
Expand Down Expand Up @@ -232,9 +239,9 @@ class Dump {
void ReadSerial(IdfxFileHandler, int, int*, DataType, void*);
void ReadDistributed(IdfxFileHandler, int, int*, int*, IdfxDataDescriptor&, void*);
void Skip(IdfxFileHandler, int, int *, DataType);
int GetLastDumpInDirectory(std::filesystem::path &);
int GetLastDumpInDirectory(fs::path &);

std::filesystem::path outputDirectory;
fs::path outputDirectory;
};


Expand Down
20 changes: 14 additions & 6 deletions src/output/vtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
#include <string>
#include <sstream>
#include <iomanip>
#include <filesystem>
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
error "Missing the <filesystem> header."
#endif
#include "vtk.hpp"
#include "version.hpp"
#include "idefix.hpp"
Expand Down Expand Up @@ -64,9 +72,9 @@ Vtk::Vtk(Input &input, DataBlock *datain, std::string filebase) {
}

if(idfx::prank==0) {
if(!std::filesystem::is_directory(outputDirectory)) {
if(!fs::is_directory(outputDirectory)) {
try {
if(!std::filesystem::create_directory(outputDirectory)) {
if(!fs::create_directory(outputDirectory)) {
std::stringstream msg;
msg << "Cannot create directory " << outputDirectory << std::endl;
IDEFIX_ERROR(msg);
Expand Down Expand Up @@ -247,7 +255,7 @@ int Vtk::Write() {
idfx::pushRegion("Vtk::Write");

IdfxFileHandler fileHdl;
std::filesystem::path filename;
fs::path filename;

timer.reset();

Expand All @@ -260,8 +268,8 @@ int Vtk::Write() {

// Check if file exists, if yes, delete it
if(this->isRoot) {
if(std::filesystem::exists(filename)) {
std::filesystem::remove(filename);
if(fs::exists(filename)) {
fs::remove(filename);
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/output/vtk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
#define OUTPUT_VTK_HPP_
#include <string>
#include <map>
#include <filesystem>
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
error "Missing the <filesystem> header."
#endif
#include "idefix.hpp"
#include "input.hpp"
#include "dataBlock.hpp"
Expand Down Expand Up @@ -158,7 +166,7 @@ class Vtk : public BaseVtk {
void WriteHeaderNodes(IdfxFileHandler);

// output directory
std::filesystem::path outputDirectory;
fs::path outputDirectory;
};

template<typename T>
Expand Down