SkelGIS  3.0
/home/helene/Documents/These/SkelGIS/SkelGIS_Library/SkelGIS_V3/skelgis/util/mpi_.hpp
Go to the documentation of this file.
00001 /*! \file mpi_.hpp
00002  *  \brief Definitions of the object Mpi_. This object contains static members to get MPI informations in the library. It also contains a parallel print of string in processors files (used for debug).
00003  */
00004 #ifndef MPIOMP_H
00005 #define MPIOMP_H
00006 
00007 #include <stdlib.h>
00008 #include <sys/stat.h>
00009 #include <sys/types.h>
00010 #include <string.h>
00011 #include <iostream>
00012 #include <fstream>
00013 #include <sstream>
00014 
00015 #include "mpi.h"
00016 
00017 namespace skelgis{
00018 
00019   //================================================================================
00020   //!  Mpi_ Class 
00021   /*!
00022     This template class defines the MPI initializations, the MPI communications
00023   */
00024   //-------------------------------------------------------------------------------
00025   class Mpi_
00026   //-------------------------------------------------------------------------------
00027   {
00028   public:
00029     //--------------------------------------
00030     //VARIABLES
00031     //--------------------------------------
00032     static int level_provided; /*!< MPI level provided */
00033     static int mpi_rank; /*!< mpi rank of the current process */
00034     static int mpi_nb; /*!< number of mpi processes */
00035     //--------------------------------------    
00036 
00037     //-------------------------------------------------------------------------------
00038     //! Constructor
00039     //-------------------------------------------------------------------------------
00040     Mpi_(){}
00041     //-------------------------------------------------------------------------------
00042 
00043     //-------------------------------------------------------------------------------
00044     //! Destructor
00045     //-------------------------------------------------------------------------------
00046     ~Mpi_(){}
00047     //-------------------------------------------------------------------------------
00048     //! Print the string str in output files
00049     /*!
00050       Only used for verifications because of synchronizations time
00051       \param str is the string to print
00052     */
00053     //-------------------------------------------------------------------------------
00054     static void print(std::string str)
00055     //-------------------------------------------------------------------------------
00056     {
00057       std::stringstream st2;
00058       st2<<"\nMPI "<<Mpi_::mpi_rank<<" - "<<" : "<<str;
00059    
00060       mkdir("outputs", 01777);
00061       std::stringstream fileStr;
00062       fileStr<<"./outputs/log_mach"<<Mpi_::mpi_rank<<".txt";
00063       std::ofstream fileW(fileStr.str().data(),std::ios_base::app);
00064       fileW.write(st2.str().data(),st2.str().size());
00065       fileW.close();
00066     }
00067     //-------------------------------------------------------------------------------
00068     //! Print the string str on screen
00069     /*!
00070       Only used for verifications because of synchronizations time
00071       \param str is the string to print
00072     */
00073     //-------------------------------------------------------------------------------
00074     static void printScreen(std::string str)
00075     //-------------------------------------------------------------------------------
00076     {
00077       std::stringstream st2;
00078       st2<<"MPI "<<Mpi_::mpi_rank<<" - "<<" : "<<str;
00079       std::cout<<st2.str()<<std::endl;
00080     }
00081   };
00082 
00083   //-------------------------------------------------------------------------------
00084   //Instances
00085   //-------------------------------------------------------------------------------
00086   int Mpi_::level_provided=0;
00087   int Mpi_::mpi_rank=0;
00088   int Mpi_::mpi_nb=0;
00089 
00090 }
00091 
00092 #endif
00093 
 All Classes Files Functions Variables Defines