Commit 6c1fdb33 authored by Jan Oliver Oelerich's avatar Jan Oliver Oelerich

Added ssb-run binary, which is the actual simulation and should be used in...

Added ssb-run binary, which is the actual simulation and should be used in conjunction with ssb-mkin. The `traditional` stemsalabim binary is used as before.
parent 060c3897
......@@ -40,6 +40,7 @@ set(INTERNAL_FILES
utilities/mpi.hpp
utilities/memory.hpp
utilities/output.hpp
utilities/initialize.hpp
utilities/algorithms.hpp
utilities/TaskQueue.hpp
utilities/timings.hpp
......@@ -57,6 +58,7 @@ add_library(stemsalabim_lib ${INTERNAL_FILES} ${EXTERNAL_FILES})
add_executable(stemsalabim stemsalabim.cpp)
add_executable(ssb-chk ssb-chk.cpp)
add_executable(ssb-mkin ssb-mkin.cpp)
add_executable(ssb-run ssb-run.cpp)
include_directories(
3rdparty/cereal/include
......@@ -76,6 +78,7 @@ target_link_libraries(stemsalabim_lib m ${LIBS})
target_link_libraries(stemsalabim stemsalabim_lib)
target_link_libraries(ssb-chk stemsalabim_lib)
target_link_libraries(ssb-mkin stemsalabim_lib)
target_link_libraries(ssb-run stemsalabim_lib)
# MPI ####################################################
......@@ -89,7 +92,7 @@ endif(MPI_LINK_FLAGS)
# installation ###########################################
install(TARGETS stemsalabim ssb-chk stemsalabim_lib
install(TARGETS stemsalabim ssb-chk ssb-mkin ssb-run stemsalabim_lib
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
......@@ -305,7 +305,7 @@ void IO::writeParams(const shared_ptr<GridManager> &gridman, const string &conf_
{
auto g = pg.defineGroup("grating");
g.att("density", p.samplingDensity());
g.att("nominal_density", p.samplingDensity());
g.att("nx", gridman->samplingX());
g.att("ny", gridman->samplingY());
g.att("slice_thickness", p.sliceThickness());
......@@ -723,7 +723,6 @@ void IO::writeTemporaryResult(unsigned int idefocus, unsigned int iconf, ScanPoi
shared_ptr<memory::buffer::number_buffer<float>> &cbuf) {
auto &mpi_env = mpi::Environment::getInstance();
int mpi_rank = mpi_env.rank();
auto tmpfile = std::ofstream(getTempFileName(), std::ios::binary | std::ios::app);
// the format is as follows:
......
......@@ -41,6 +41,7 @@
#include "utilities/output.hpp"
#include "utilities/TaskQueue.hpp"
#include "classes/FPConfManager.hpp"
#include "utilities/initialize.hpp"
using namespace std;
using namespace chrono;
......@@ -112,66 +113,5 @@ void Params::initFromCLI(int argc, const char **argv) {
int main(int argc, const char **argv) {
auto &mpi_env = mpi::Environment::getInstance();
// Initialization of the input NC file is done only by the master
// MPI proc, in case the tool is run differently.
if(mpi_env.isSlave()) {
return 0;
}
Params &p = Params::getInstance();
p.initFromCLI(argc, argv);
p.readParamsFromString(algorithms::readTextFile(p.paramsFileName()));
p.setCell(IO::initCrystalFromXYZFile(p.crystalFilename()));
auto fpman = std::make_shared<FPConfManager>(p.cell());
auto gridman = std::make_shared<GridManager>(p.cell());
auto io = std::make_shared<IO>();
fpman->generateDisplacements();
gridman->generateGrids();
io->initNCFile(gridman, p.cell());
io->writeParams(gridman);
io->writeGrids(gridman);
SimulationStateManager state_manager(gridman);
// loop over simulations
for(SimulationState &st: state_manager) {
fpman->setConfiguration(st.iteration());
// in each configuration, assign atoms to the corresponding slices.
fpman->assignAtomsToSlices(gridman);
io->writeCrystal(fpman, p.cell(), gridman);
if(p.storedPotentials()) {
vector<vector<vector<float>>> vz(gridman->slices().size());
TaskQueue slice_work;
slice_work.append(gridman->slices());
vector<thread> threads;
for(unsigned int nt = 0; nt < p.numberOfThreads(); nt++) {
threads.emplace_back([&] {
unsigned int slic_index;
while(slice_work.pop(slic_index)) {
vz[slic_index] = gridman->slices()[slic_index]->calculatePotential(fpman, gridman);
slice_work.finish(slic_index);
}
});
}
slice_work.waitUntilFinished();
for(auto &t : threads)
t.join();
io->writePotentials(fpman, vz);
}
}
initialize_input_file(argc, argv);
}
\ No newline at end of file
/*
* STEMsalabim: Magical STEM image simulations
*
* Copyright (c) 2016-2018 Jan Oliver Oelerich <jan.oliver.oelerich@physik.uni-marburg.de>
* Copyright (c) 2016-2018 Structure and Technology Research Laboratory, Philipps-Universität Marburg, Germany
*
* This program 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <iostream>
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
#include "3rdparty/args/args.hxx"
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#include "3rdparty/sole/sole.hpp"
#include "utilities/Wave.hpp"
#include "classes/Simulation.hpp"
using namespace std;
using namespace stemsalabim;
void Params::initFromCLI(int argc, const char **argv) {
using namespace args;
ArgumentParser parser("STEMsalabim usage instructions.", "Please refer to the User documentation.");
HelpFlag help(parser, "help", "Display this help menu", {'h', "help"});
ValueFlag<string> params(parser, "params", "The parameter file path.", {'p', "params"});
ValueFlag<unsigned int> num_threads(parser, "num-threads", "The number of threads per MPI proc.", {"num-threads"});
ValueFlag<unsigned int> pkgsize(parser, "package-size", "Number of tasks in a MPI work package.", {"package-size"});
ValueFlag<string> output_file(parser, "output-file", "The output file path.", {'o', "output-file"});
ValueFlag<string> tmp_dir(parser, "tmp-dir", "The path to the temporary directory.", {"tmp-dir"});
Flag stored_potentials(parser, "stored-potentials", "Work with stored potentials", {"stored-potentials"});
try {
parser.ParseCLI(argc, argv);
} catch(Help &) {
cout << parser;
exit(0);
} catch(ParseError &e) {
cerr << e.what() << endl;
cerr << parser;
exit(1);
}
if(argc > 1) {
vector<string> all_args;
all_args.assign(argv + 1, argv + argc);
_command_line_arguments = algorithms::join(all_args, " ");
}
if(stored_potentials) {
_cli_options.push_back(params.Name());
_stored_potentials = true;
}
if(params) {
_cli_options.push_back(params.Name());
_param_file = get(params);
} else {
output::error("a parameter file MUST be specified!\n");
}
if(num_threads) {
_cli_options.push_back(num_threads.Name());
_num_threads = get(num_threads);
}
if(pkgsize) {
_cli_options.push_back(pkgsize.Name());
_work_package_size = get(pkgsize);
}
if(output_file) {
_cli_options.push_back(output_file.Name());
_output_file = get(output_file);
}
if(tmp_dir) {
_cli_options.push_back(tmp_dir.Name());
_tmp_dir = get(tmp_dir);
}
_uuid = sole::uuid4().str();
}
int main(int argc, const char **argv) {
auto &mpi_env = mpi::Environment::getInstance();
Params &p = Params::getInstance();
p.initFromCLI(argc, argv);
if(mpi_env.isMaster()) {
p.readParamsFromNCFile();
p.setCell(IO::initCrystalFromNCFile(p.paramsFileName()));
}
if(mpi_env.isMpi())
p.broadcast(mpi::Environment::MASTER);
// create the simulation instance an pass the parameters instance
// to it.
Simulation s;
s.init();
s.run();
}
\ No newline at end of file
......@@ -36,6 +36,7 @@
#include "utilities/Wave.hpp"
#include "classes/Simulation.hpp"
#include "utilities/initialize.hpp"
using namespace std;
using namespace stemsalabim;
......@@ -50,8 +51,6 @@ void Params::initFromCLI(int argc, const char **argv) {
ValueFlag<unsigned int> pkgsize(parser, "package-size", "Number of tasks in a MPI work package.", {"package-size"});
ValueFlag<string> output_file(parser, "output-file", "The output file path.", {'o', "output-file"});
ValueFlag<string> tmp_dir(parser, "tmp-dir", "The path to the temporary directory.", {"tmp-dir"});
Flag stored_potentials(parser, "stored-potentials", "Work with stored potentials", {"stored-potentials"});
try {
parser.ParseCLI(argc, argv);
......@@ -70,11 +69,6 @@ void Params::initFromCLI(int argc, const char **argv) {
_command_line_arguments = algorithms::join(all_args, " ");
}
if(stored_potentials) {
_cli_options.push_back(params.Name());
_stored_potentials = true;
}
if(params) {
_cli_options.push_back(params.Name());
_param_file = get(params);
......@@ -107,15 +101,13 @@ void Params::initFromCLI(int argc, const char **argv) {
int main(int argc, const char **argv) {
auto &mpi_env = mpi::Environment::getInstance();
Params &p = Params::getInstance();
p.initFromCLI(argc, argv);
if(mpi_env.isMaster()) {
p.readParamsFromNCFile();
p.setCell(IO::initCrystalFromNCFile(p.paramsFileName()));
}
initialize_input_file(argc, argv);
p.readParamsFromNCFile();
p.setCell(IO::initCrystalFromNCFile(p.paramsFileName()));
if(mpi_env.isMpi())
p.broadcast(mpi::Environment::MASTER);
......
/*
* STEMsalabim: Magical STEM image simulations
*
* Copyright (c) 2016-2018 Jan Oliver Oelerich <jan.oliver.oelerich@physik.uni-marburg.de>
* Copyright (c) 2016-2018 Structure and Technology Research Laboratory, Philipps-Universität Marburg, Germany
*
* This program 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// This namespace contains only static methods to print out stuff to stdout.
#ifndef INITIALIZE_HPP_
#define INITIALIZE_HPP_
#include <thread>
#include "mpi.hpp"
#include "TaskQueue.hpp"
#include "../classes/Params.hpp"
#include "../classes/IO.hpp"
#include "../classes/FPConfManager.hpp"
#include "../classes/SimulationState.hpp"
namespace stemsalabim {
void initialize_input_file(int argc, const char **argv) {
auto &mpi_env = mpi::Environment::getInstance();
Params &p = Params::getInstance();
p.initFromCLI(argc, argv);
if(mpi_env.isMaster()) {
p.readParamsFromString(algorithms::readTextFile(p.paramsFileName()));
p.setCell(IO::initCrystalFromXYZFile(p.crystalFilename()));
auto fpman = std::make_shared<FPConfManager>(p.cell());
auto gridman = std::make_shared<GridManager>(p.cell());
auto io = std::make_shared<IO>();
fpman->generateDisplacements();
gridman->generateGrids();
io->initNCFile(gridman, p.cell());
io->writeParams(gridman);
io->writeGrids(gridman);
SimulationStateManager state_manager(gridman);
// loop over simulations
for(SimulationState &st: state_manager) {
fpman->setConfiguration(st.iteration());
// in each configuration, assign atoms to the corresponding slices.
fpman->assignAtomsToSlices(gridman);
io->writeCrystal(fpman, p.cell(), gridman);
if(p.storedPotentials()) {
std::vector<std::vector<std::vector<float>>> vz(gridman->slices().size());
TaskQueue slice_work;
slice_work.append(gridman->slices());
std::vector<std::thread> threads;
for(unsigned int nt = 0; nt < p.numberOfThreads(); nt++) {
threads.emplace_back([&] {
unsigned int slic_index;
while(slice_work.pop(slic_index)) {
vz[slic_index] = gridman->slices()[slic_index]->calculatePotential(fpman, gridman);
slice_work.finish(slic_index);
}
});
}
slice_work.waitUntilFinished();
for(auto &t : threads)
t.join();
io->writePotentials(fpman, vz);
}
}
}
}
}
#endif // INITIALIZE_HPP_
\ No newline at end of file
......@@ -205,8 +205,6 @@ namespace stemsalabim {
template<typename T>
void put(const std::vector<T> &vals) {
auto l = len();
auto data_len = std::accumulate(l.begin(), l.end(), 1, std::multiplies<>());
assert(vals.size() == (size_t)data_len);
assert(nc_type_def<T>() == _type);
CHK(nc_put_var(_parentid, _id, vals.data()));
}
......
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