[cig-commits] [commit] master: Correctly calculate memory usage (63db716)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Tue Dec 2 13:56:01 PST 2014


Repository : https://github.com/geodynamics/vq

On branch  : master
Link       : https://github.com/geodynamics/vq/compare/06902a05cf4d70bc94c85d1c195c073d4e74cdad...c935dfd33f870a081b6c01cce97a060ad1cbdbda

>---------------------------------------------------------------

commit 63db71686196e71d97683a8d2a33bc9a730d39c4
Author: Eric Heien <emheien at ucdavis.edu>
Date:   Wed Nov 12 16:45:25 2014 -0800

    Correctly calculate memory usage


>---------------------------------------------------------------

63db71686196e71d97683a8d2a33bc9a730d39c4
 src/simulation/GreensInit.cpp | 43 +++++++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/src/simulation/GreensInit.cpp b/src/simulation/GreensInit.cpp
index 21537f4..794d894 100644
--- a/src/simulation/GreensInit.cpp
+++ b/src/simulation/GreensInit.cpp
@@ -81,12 +81,9 @@ void GreensInit::init(SimFramework *_sim) {
     GreensFuncCalcBarnesHut bh_calc;
     GreensFuncCalcStandard  gstandard_calc;
     GreensFuncFileParse     file_parse;
-    double                  start_time;
-    double                  shear_bytes, normal_bytes;
-    int                     shear_ind, norm_ind;
     std::string             space_vals[] = {"bytes", "kilobytes", "megabytes", "gigabytes", "terabytes", "petabytes"};
 
-    start_time = sim->curTime();
+    double start_time = sim->curTime();
 
     switch (sim->getGreensCalcMethod()) {
         case GREENS_FILE_PARSE:
@@ -113,21 +110,27 @@ void GreensInit::init(SimFramework *_sim) {
     sim->console() << std::endl << "# Greens function took " << sim->curTime() - start_time << " seconds." << std::endl;
 
     // Determine Green's function matrix memory usage
-    // TODO: global reduction for parallel simulations
-    shear_bytes = sim->greenShear()->mem_bytes();
-    normal_bytes = sim->greenNormal()->mem_bytes();
-    shear_ind = norm_ind = 0;
-
-    while (shear_bytes > 1024.0) {
-        shear_bytes /= 1024.0;
-        shear_ind++;
+    double shear_bytes = sim->greenShear()->mem_bytes();
+    double normal_bytes = sim->greenNormal()->mem_bytes();
+    int shear_ind = (log(shear_bytes)/log(2))/10;
+    int norm_ind = (log(shear_bytes)/log(2))/10;
+    double abbr_shear_bytes = shear_bytes/pow(2,shear_ind*10);
+    double abbr_normal_bytes = normal_bytes/pow(2,norm_ind*10);
+
+    sim->console() << "# Greens shear matrix takes " << abbr_shear_bytes << " " << space_vals[shear_ind] << std::endl;
+    sim->console() << "# Greens normal matrix takes " << abbr_normal_bytes << " " << space_vals[norm_ind] << std::endl;
+    
+#ifdef MPI_C_FOUND
+    if (sim->getWorldSize() > 1) {
+        double global_shear_bytes, global_normal_bytes;
+        MPI_Reduce(&shear_bytes, &global_shear_bytes, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
+        MPI_Reduce(&normal_bytes, &global_normal_bytes, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
+        int global_shear_ind = (log(global_shear_bytes)/log(2))/10;
+        int global_norm_ind = (log(global_normal_bytes)/log(2))/10;
+        double abbr_global_shear_bytes = global_shear_bytes/pow(2,global_shear_ind*10);
+        double abbr_global_normal_bytes = global_normal_bytes/pow(2,global_norm_ind*10);
+        sim->console() << "# Global Greens shear matrix takes " << abbr_global_shear_bytes << " " << space_vals[global_shear_ind] << "." << std::endl;
+        sim->console() << "# Global Greens normal matrix takes " << abbr_global_normal_bytes << " " << space_vals[global_norm_ind] << "." << std::endl;
     }
-
-    while (normal_bytes > 1024.0) {
-        normal_bytes /= 1024.0;
-        norm_ind++;
-    }
-
-    sim->console() << "# Greens shear matrix takes " << shear_bytes << " " << space_vals[shear_ind] << "." << std::endl;
-    sim->console() << "# Greens normal matrix takes " << normal_bytes << " " << space_vals[norm_ind] << "." << std::endl;
+#endif
 }



More information about the CIG-COMMITS mailing list