Page MenuHomec4science

AMEL.cc
No OneTemporary

File Metadata

Created
Thu, Sep 5, 06:31
/* ./amel/AMEL.cpp
**********************************
author : Guillaume ANCIAUX (guillaume.anciaux@epfl.ch, g.anciaux@laposte.net)
The LibMultiScale is a C++ parallel framework for the multiscale
coupling methods dedicated to material simulations. This framework
provides an API which makes it possible to program coupled simulations
and integration of already existing codes.
This Project is done in a collaboration between
EPFL within ENAC-LSMS (http://lsms.epfl.ch/) and
INRIA Bordeaux, ScAlApplix (http://www.labri.fr/projet/scalapplix/).
This software is governed by the CeCILL-C license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL-C
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL-C license and that you accept its terms.
***********************************/
/* -------------------------------------------------------------------------- */
#include "lm_common.hh"
#include "domain_multiscale.hh"
#include "algebraic_parser.hh"
#include "action_manager.hh"
using namespace libmultiscale;
/* -------------------------------------------------------------------------- */
#include <iostream>
#include <iomanip>
/* -------------------------------------------------------------------------- */
#ifdef LIBMULTISCALE_USE_QVIEW
#include <libqview.h>
#endif
/* -------------------------------------------------------------------------- */
#ifdef USING_EPSN
#include <iostream>
#include <fstream>
#include <sstream>
#endif
/* -------------------------------------------------------------------------- */
#include <sys/types.h>
#include <unistd.h>
#include <mpi.h>
/* -------------------------------------------------------------------------- */
#include <stdexcept>
Real lastdump = -1e30;
Real lastStep = 0;
void printState(){
if (lm_my_proc_id != 0) return;
struct timespec gtime;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&gtime);
if ( gtime.tv_sec - lastdump < 2) return;
Real nstep_done = - lastStep+current_step;
std::stringstream info_steps;
info_steps << std::setw(3) << std::setfill(' ')
<< 100*current_step/nb_step << "% - "
#ifdef USE_COMPACT_STATUS
<< "step"
#else
<< "passing step "
#endif
<< std::setw(5) << std::setfill(' ') << current_step << "/"
<< std::setw(5) << std::setfill(' ') << nb_step;
if(current_step > 0){
Real step_per_seconds = nstep_done/(gtime.tv_sec - lastdump);
Real remaining_time = 1. * (nb_step-current_step) / step_per_seconds;
UInt remaining_hours = int(remaining_time/60/60);
UInt remaining_minutes = int(remaining_time/60 - remaining_hours*60);
UInt remaining_seconds = int(remaining_time-remaining_minutes*60 - remaining_hours*60*60);
info_steps << " "
<< std::setw(5) << std::setfill(' ') << step_per_seconds
#ifdef USE_COMPACT_STATUS
<< "/sec. ETA: "
#else
<< " steps/seconds "
<< "remaining "
#endif
<< std::setw(5) << std::setfill(' ') << remaining_hours
#ifdef USE_COMPACT_STATUS
<< ":"
#else
<< " hours "
#endif
#ifdef USE_COMPACT_STATUS
<< std::setw(2) << std::setfill('0') << remaining_minutes
<< ":"
#else
<< std::setw(2) << std::setfill(' ') << remaining_minutes
<< " minutes "
#endif
#ifdef USE_COMPACT_STATUS
<< std::setw(2) << std::setfill('0') << remaining_seconds;
#else
<< std::setw(2) << std::setfill(' ') << remaining_seconds
<< " seconds";
#endif
}
std::string clown = info_steps.str();
//std::cerr << "\r" << clown;
std::cerr << info_steps.str() << std::endl;
lastStep = current_step;
lastdump = gtime.tv_sec;
}
/* -------------------------------------------------------------------------- */
//void echange_args(const string &* argv,char **my_args);
extern std::string lm_release_info;
/* -------------------------------------------------------------------------- */
static void Usage(const std::string & name){
std::cout << "Usage : " << name << " config_file nb_time_step\n"
<< "\t config_file : global config file of the simulation\n"
<< "\t nb_time_step : number of time step wanted to be done (>=0)\n";
std::cout << "*****************************************" << std::endl;
std::cout << "release info" << std::endl;
std::cout << "*****************************************" << std::endl;
std::cout << lm_release_info << std::endl;
lm_exit(LM_EXIT_FAILURE);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char ** argv)
{
loadModules(argc,argv); // loading the modules macro
if (argc != 3){
if (lm_my_proc_id == 0)
Usage(argv[0]);
lm_exit(LM_EXIT_FAILURE);
}
nb_step = atoi(argv[2]);
nb_step_next_event = nb_step;
if (nb_step == UINT_MAX)
Usage(argv[0]);
MPI_Barrier(MPI_COMM_WORLD);
DOWAIT_AT_STARTUP;
STARTTIMER("Init");
DomainMultiScale & dom = DomainMultiScale::getManager();
dom.build(argv[1]);
ActionManager & actions = dom.getActionManager();
STOPTIMER("Init");
nb_step+= current_step;
#ifdef USING_EPSN
std::ofstream epsn_log;
struct timeval timer_epsn_start;
struct timeval timer_epsn_stop;
struct timeval result;
std::stringstream epsn_log_filename;
epsn_log_filename << "epsn_log_" << std::setfill('0') << std::setw(5) << lm_my_proc_id << ".log";
epsn_log.open(epsn_log_filename.str().c_str(), std::ios_base::out);
if (epsn_itfc->isNodeInitialized()) {
UInt epsn_status = 0;
// EPSN Ready
DUMP("EPSN is going to be READY...", DBG_INFO_STARTUP);
epsn_status = epsn_itfc->ready();
if (!epsn_status) {
FATAL("error on EPSN Node ready operation\n");
}
DUMP("EPSN READY",DBG_INFO_STARTUP);
// the main loop
DUMP("EPSN Begin HTG",DBG_INFO_STARTUP);
epsn_itfc->beginHTM();
epsn_itfc->beginLoop("main");
DUMP("simulation ready to start for EPSN", DBG_INFO_STARTUP);
}
#endif
MPI_Barrier(MPI_COMM_WORLD);
bool shouldPrintState = true;
#ifdef LIBMULTISCALE_USE_QVIEW
QView qv;
qv.setMode(NET_MODE);
qv.initLibQview(lm_my_proc_id);
qv.beginTask("main",nb_step);
shouldPrintState = false;
#endif //USING_QVIEW
char * varenv = getenv("PRINT_STATE");
if (varenv) shouldPrintState = true;
STARTTIMER("Main loop");
Real min_dt = dom.getTimeStep();
current_time = current_step*min_dt;
for (; current_step < nb_step ; ++current_step, current_time += min_dt){
#ifdef USING_EPSN
gettimeofday(&timer_epsn_start,NULL);
if (epsn_itfc->isNodeInitialized())
epsn_itfc->beginTask("body");
#endif
#ifdef LIBMULTISCALE_USE_QVIEW
qv.setCurrentStep(current_step);
#endif //USING_QVIEW
if (shouldPrintState) printState();
try {
current_stage = PRE_DUMP;
actions.action();
current_stage = PRE_STEP1;
actions.action();
STARTTIMER("performStep1");
dom.performStep1();
STOPTIMER("performStep1");
dom.coupling(COUPLING_STEP1);
current_stage = PRE_STEP2;
actions.action();
STARTTIMER("performStep2");
dom.performStep2();
STOPTIMER("performStep2");
dom.coupling(COUPLING_STEP2);
current_stage = PRE_STEP3;
actions.action();
STARTTIMER("performStep3");
dom.performStep3();
STOPTIMER("performStep3");
STARTTIMER("Coupling");
dom.coupling(COUPLING_STEP3);
STOPTIMER("Coupling");
current_stage = PRE_STEP4;
actions.action();
dom.coupling(COUPLING_STEP4);
} catch (std::runtime_error & err) {
std::stringstream error_stream;
error_stream << " at stage " << current_stage << ": Caught '"
<< err.what() << "'";
LM_FATAL(error_stream.str());
}
#ifdef USING_EPSN
if (epsn_itfc->isNodeInitialized())
epsn_itfc->endTask("body");
gettimeofday(&timer_epsn_stop,NULL);
result.tv_sec = timer_epsn_stop.tv_sec - timer_epsn_start.tv_sec;
if ( (result.tv_usec = timer_epsn_stop.tv_usec - timer_epsn_start.tv_usec) < 0 ) {
--result.tv_sec;
result.tv_usec += 1000000;
}
Real time_epsn = result.tv_sec * 1000.0 + result.tv_usec / 1000.0;
epsn_log << lm_my_proc_id << " " << current_step << " " << time_epsn << std::endl;
#endif
// MPI_Barrier(MPI_COMM_WORLD);
}
#ifdef LIBMULTISCALE_USE_QVIEW
qv.endTask();
#endif //USING_QVIEW
#ifdef USING_EPSN
if (epsn_itfc->isNodeInitialized()) {
epsn_itfc->endLoop("main");
epsn_itfc->endHTM();
}
#endif
current_stage = PRE_DUMP;
actions.action();
current_stage = PRE_STEP1;
actions.action();
STOPTIMER("Main loop");
dom.destroy();
closeModules(); // closing the modules macro
std::cerr << std::endl;
lm_exit(LM_EXIT_SUCCESS);
}
/* -------------------------------------------------------------------------- */

Event Timeline