Dhairya Malhotra 7 years ago
parent
commit
ae93d94ffe
4 changed files with 20 additions and 17 deletions
  1. 1 6
      include/sctl/comm.hpp
  2. 8 0
      include/sctl/comm.txx
  3. 3 3
      include/sctl/profile.hpp
  4. 8 8
      include/sctl/profile.txx

+ 1 - 6
include/sctl/comm.hpp

@@ -92,12 +92,7 @@ class Comm {
   };
 
 #ifdef SCTL_HAVE_MPI
-  void Init(const MPI_Comm mpi_comm) {
-    #pragma omp critical(SCTL_COMM_DUP)
-    MPI_Comm_dup(mpi_comm, &mpi_comm_);
-    MPI_Comm_rank(mpi_comm_, &mpi_rank_);
-    MPI_Comm_size(mpi_comm_, &mpi_size_);
-  }
+  void Init(const MPI_Comm mpi_comm);
 
   Vector<MPI_Request>* NewReq() const;
 

+ 8 - 0
include/sctl/comm.txx

@@ -38,6 +38,7 @@ inline Comm Comm::World() {
 
 inline Comm& Comm::operator=(const Comm& c) {
 #ifdef SCTL_HAVE_MPI
+  MPI_Comm_free(&mpi_comm_);
   Init(c.mpi_comm_);
 #endif
   return *this;
@@ -931,6 +932,13 @@ inline Vector<MPI_Request>* Comm::NewReq() const {
   return &request;
 }
 
+void Comm::Init(const MPI_Comm mpi_comm) {
+  #pragma omp critical(SCTL_COMM_DUP)
+  MPI_Comm_dup(mpi_comm, &mpi_comm_);
+  MPI_Comm_rank(mpi_comm_, &mpi_rank_);
+  MPI_Comm_size(mpi_comm_, &mpi_size_);
+}
+
 inline void Comm::DelReq(Vector<MPI_Request>* req_ptr) const {
   if (req_ptr) req.push(req_ptr);
 }

+ 3 - 3
include/sctl/profile.hpp

@@ -17,10 +17,10 @@ class Comm;
 
 class Profile {
  public:
-  static Long Add_FLOP(Long inc);
-
   static Long Add_MEM(Long inc);
 
+  static Long Add_FLOP(Long inc);
+
   static bool Enable(bool state);
 
   static void Tic(const char* name_, const Comm* comm_ = nullptr, bool sync_ = false, Integer level = 0);
@@ -53,8 +53,8 @@ class Profile {
     std::vector<Long> max_m_log;
 
     ProfileData() {
-      FLOP = 0;
       MEM = 0;
+      FLOP = 0;
       enable_state = false;
       enable_depth = 0;
     }

+ 8 - 8
include/sctl/profile.txx

@@ -11,14 +11,6 @@ namespace SCTL_NAMESPACE {
 
 #if SCTL_PROFILE >= 0
 
-inline Long Profile::Add_FLOP(Long inc) {
-  Long& FLOP = ProfData().FLOP;
-  Long orig_val = FLOP;
-#pragma omp atomic update
-  FLOP += inc;
-  return orig_val;
-}
-
 inline Long Profile::Add_MEM(Long inc) {
   std::vector<Long>& max_mem = ProfData().max_mem;
   Long& MEM = ProfData().MEM;
@@ -29,6 +21,14 @@ inline Long Profile::Add_MEM(Long inc) {
   return orig_val;
 }
 
+inline Long Profile::Add_FLOP(Long inc) {
+  Long& FLOP = ProfData().FLOP;
+  Long orig_val = FLOP;
+#pragma omp atomic update
+  FLOP += inc;
+  return orig_val;
+}
+
 inline bool Profile::Enable(bool state) {
   bool& enable_state = ProfData().enable_state;
   bool orig_val = enable_state;