]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add MPILogInitAll helper class for mpi tests
authorTimo Heister <timo.heister@gmail.com>
Thu, 30 May 2013 00:35:40 +0000 (00:35 +0000)
committerTimo Heister <timo.heister@gmail.com>
Thu, 30 May 2013 00:35:40 +0000 (00:35 +0000)
git-svn-id: https://svn.dealii.org/trunk@29666 0785d39b-7218-0410-832d-ea1e28bc413d

tests/tests.h

index 2454dacb734ea694e811f091c049803a92ab3d14..90fc33ab8234c14697aad205af3607a346a7f9cf 100644 (file)
@@ -90,6 +90,68 @@ mpi_initlog(const char* filename, bool console=false)
       deallog.threshold_float(1.e-8);
     }
 }
+  
+
+
+/* helper class to include the deallogs of all processors
+   on proc 0 */
+class MPILogInitAll
+{
+  public:
+    MPILogInitAll(const char* filename, bool console=false)
+                   : m_filename(filename)
+      {
+       unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+       deallogname = output_file_for_mpi(JobIdentifier::base_name(filename));
+       if (myid != 0)
+         deallogname = deallogname + Utilities::int_to_string(myid);
+       deallogfile.open(deallogname.c_str());
+       deallog.attach(deallogfile);
+       if (!console)
+         deallog.depth_console(0);
+
+//TODO: Remove this line and replace by test_mode()
+       deallog.threshold_float(1.e-8);
+       deallog.push(Utilities::int_to_string(myid));
+      }
+
+    ~MPILogInitAll()
+      {
+       deallog.pop();
+       MPI_Barrier(MPI_COMM_WORLD);
+       
+       unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+       unsigned int nproc = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD);
+
+       if (myid==0)
+         {     
+           for (unsigned int i=1;i<nproc;++i)
+             {
+               std::string filename = output_file_for_mpi(JobIdentifier::base_name(m_filename.c_str()))
+                                      + Utilities::int_to_string(i);
+               std::ifstream in(filename.c_str());
+               Assert (in, ExcIO());
+               
+               while (in)
+                 {
+                   std::string s;
+                   std::getline(in, s);
+                   deallog.get_file_stream() << s << "\n";
+                 }
+               in.close();         
+               std::remove (filename.c_str());
+             }
+         }
+      }
+  private:
+
+    std::string m_filename;
+    
+};
+
+
+
+
 
 
 #ifndef DEAL_II_STACKTRACE_SWITCH

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.