Commit 704ebaaf authored by Vít Hanousek's avatar Vít Hanousek
Browse files

TMP: Simple cummulative log into file in my home directory.

parent f6ee280c
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
@@ -25,6 +25,11 @@
#include <TNL/Solvers/PDE/SemiImplicitTimeStepper.h>
#include <TNL/Solvers/PDE/PDESolverTypeResolver.h>

#include <omp.h>
#include <sstream>
#include <chrono>
#include <thread>  

namespace TNL {
namespace Solvers {   

@@ -390,6 +395,48 @@ bool SolverStarter< ConfigTag > :: runPDESolver( Problem& problem,
   writeEpilog( logFile, solver );
   logFile.close();

   //write log in common logfile

   //char * of dimension...
   std::stringstream str;
   str << problem.getMesh()->getDistributedMesh()->getGlobalGrid().getDimensions();

   char buf[ 2048 ];
   snprintf( buf,2048, "Dim: %d; Dof: %s; TimeStep: %f; TimeFinal: %f; MPI: %d; Distr: %s; OpenMPperMPI: %d; Device: %s;  RunTime: %f; ComputeTime: %f; IOTime: %f;\n",
                        problem.getMesh()->getMeshDimension(),//Dim
                        str.str().c_str(),//Dof - size
                        parameters.getParameter< double >( "time-step" ),
                        parameters.getParameter< double >( "final-time"),
                        Problem::CommunicatorType::GetSize(Problem::CommunicatorType::AllGroup),//MPI count
                        problem.getMesh()->getDistributedMesh()->printProcessDistr().getString(), //MPI distr
                        omp_get_num_threads(), //OMPperMPI
                        parameters.getParameter< String >( "device" ).getString(),
                        this->totalTimer.getRealTime(),
                        this->computeTimer.getRealTime(),
                        this->ioTimer.getRealTime()
            );


   std::cout <<std::endl << std::endl<< buf <<std::endl;

   if(Problem::CommunicatorType::GetRank(Problem::CommunicatorType::AllGroup)==0)
   {
       std::ofstream ofs;
       for(int i=0;i<20;i++)
       {
           ofs.open ("/home/hanouvit/heatequationtest.log", std::ofstream::out | std::ofstream::app);
           if(ofs.fail())
           {
                std::this_thread::sleep_for(std::chrono::seconds(5));
                continue;
           }
           ofs << buf;
           ofs.close();
           break;
       }
   }
   

   return returnCode;
}

@@ -417,6 +464,7 @@ bool SolverStarter< ConfigTag > :: writeEpilog( std::ostream& str, const Solver&
   sprintf( buf, "%f %%", 100 * ( ( double ) this->totalTimer.getCPUTime() ) / this->totalTimer.getRealTime() );
   logger.writeParameter< char* >( "CPU usage:", buf );
   logger.writeSeparator();

   return true;
}