Commit fd64a21c authored by kraus's avatar kraus

Merge branch...

Merge branch '644-sampler-cleanup-with-keep-option-not-working-when-directory-is-present-2' into 'master'

Resolve "Sampler cleanup with KEEP option not working when directory is present"

Closes #644

See merge request !499
parents 24046b7f 2bfa5c5c
//
// Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
//
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
#ifndef GSLERRORHANDLING_H
#define GSLERRORHANDLING_H
#include "Utilities/OpalException.h"
inline void handleGSLErrors(const char *reason,
const char *file,
int /*line*/,
int /*gsl_errno*/) {
throw OpalException(file, reason);
}
#endif
\ No newline at end of file
......@@ -46,6 +46,7 @@
#include "Utility/IpplException.h"
#include "Utility/IpplInfo.h"
#include "Utility/IpplTimings.h"
#include "GSLErrorHandling.h"
#include <gsl/gsl_errno.h>
......@@ -61,13 +62,6 @@ Ippl *ippl;
Inform *gmsg;
namespace {
void errorHandlerGSL(const char *reason,
const char *file,
int /*line*/,
int /*gsl_errno*/) {
throw OpalException(file, reason);
}
void printStdoutHeader() {
OPALTimer::Timer simtimer;
std::string dateStr(simtimer.date());
......@@ -146,7 +140,7 @@ int main(int argc, char *argv[]) {
H5SetVerbosityLevel(1); //65535);
gsl_set_error_handler(&errorHandlerGSL);
gsl_set_error_handler(&handleGSLErrors);
static IpplTimings::TimerRef mainTimer = IpplTimings::getTimer("mainTimer");
IpplTimings::startTimer(mainTimer);
......
......@@ -376,9 +376,8 @@ void OpalSimulation::run() {
//FIXME: this seems to crash OPAL in some cases
//redirectOutToFile();
#ifdef SUPRESS_OUTPUT
//XXX: hack to disable output to stdout and stderr
//XXX: hack to disable output to stdout
std::cout.setstate(std::ios::failbit);
// std::cerr.setstate(std::ios::failbit);
#endif
// now we can run the simulation
run_opal(arg, inputFileName.str(), restartStep, Options::infoLevel, Options::warnLevel, comm_);
......@@ -386,7 +385,6 @@ void OpalSimulation::run() {
//restoreOut();
#ifdef SUPRESS_OUTPUT
std::cout.clear();
std::cerr.clear();
#endif
} catch(OpalException *ex) {
......@@ -394,13 +392,12 @@ void OpalSimulation::run() {
//restoreOut();
#ifdef SUPRESS_OUTPUT
std::cout.clear();
std::cerr.clear();
#endif
std::cout << "Opal exception during simulation run: \n"
std::cerr << "Opal exception during simulation run: \n"
<< ex->where() << "\n"
<< ex->what() << std::endl;
std::cout << "Continuing 2, disregarding this simulation.."
std::cerr << "Continuing, disregarding this simulation.."
<< std::endl;
} catch(ClassicException *ex) {
......@@ -408,14 +405,26 @@ void OpalSimulation::run() {
//restoreOut();
#ifdef SUPRESS_OUTPUT
std::cout.clear();
std::cerr.clear();
#endif
std::cout << "Classic exception during simulation run: \n"
std::cerr << "Classic exception during simulation run: \n"
<< ex->where() << "\n"
<< ex->what() << std::endl;
std::cout << "Continuing 3, disregarding this simulation.."
std::cerr << "Continuing, disregarding this simulation.."
<< std::endl;
} catch(std::exception &ex) {
#ifdef SUPRESS_OUTPUT
std::cout.clear();
#endif
std::cerr << "Exception occured during simulation run: \n"
<< ex.what() << std::endl
<< "Continuing, disregarding this simulation.." << std::endl;
} catch(...) {
#ifdef SUPRESS_OUTPUT
std::cout.clear();
#endif
std::cerr << "Unknown exception occured during simulation run.\n"
<< "Continuing, disregarding this simulation.." << std::endl;
}
......@@ -424,7 +433,7 @@ void OpalSimulation::run() {
delete[] inputfile;
err = chdir(pwd_.c_str());
if (err != 0) {
std::cout << "Cannot chdir to "
std::cerr << "Cannot chdir to "
<< pwd_ << std::endl;
}
}
......@@ -640,10 +649,13 @@ void OpalSimulation::cleanUp(const std::vector<std::string>& keep) {
try {
int my_rank = 0;
MPI_Comm_rank(comm_, &my_rank);
if (my_rank == 0) {
fs::path p(simulationDirName_.c_str());
if (my_rank != 0) {
return;
}
fs::path p(simulationDirName_.c_str());
{
fs::directory_iterator it{p};
while ( it != fs::directory_iterator{} ) {
while (it != fs::directory_iterator{}) {
std::string extension = Util::toUpper(fs::extension(it->path().filename()));
// remove .
......@@ -651,7 +663,16 @@ void OpalSimulation::cleanUp(const std::vector<std::string>& keep) {
auto result = std::find(keep.begin(), keep.end(), extension);
if ( result == keep.end() ) {
if ( result == keep.end() && ! fs::is_directory(it->path())) {
fs::remove(it->path());
}
++it;
}
}
{
fs::directory_iterator it{p};
while (it != fs::directory_iterator{}) {
if (fs::is_directory(it->path()) && fs::is_empty(it->path())) {
fs::remove(it->path());
}
++it;
......
......@@ -20,6 +20,10 @@ extern Inform *gmsg;
#include "Message/Communicate.h"
#include "GSLErrorHandling.h"
#include <gsl/gsl_errno.h>
#include <fstream>
#include <iostream>
#include <limits>
......@@ -45,6 +49,8 @@ int run_opal(char */*args*/[], std::string inputfile, int restartStep,
amrex::Initialize(comm);
#endif
gsl_set_error_handler(&handleGSLErrors);
OpalData *opal = OpalData::getInstance();
Configure::configure();
......@@ -98,4 +104,4 @@ int run_opal(char */*args*/[], std::string inputfile, int restartStep,
output.close();
return 0;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment