From 79f70729e1103e0884f2c26f5f9648ff8bc5bd0a Mon Sep 17 00:00:00 2001
From: ROUZAUD-CORNABAS Jonathan <jonathan.rouzaud-cornabas@inria.fr>
Date: Tue, 25 Jun 2019 16:42:11 +0200
Subject: [PATCH] The 6 versions (SIMD/Vanilla + No Tree/Tree/LightTree) are
 validated against each other

---
 CMakeLists.txt                         |  9 +++-
 examples/basic/param.in                | 61 --------------------------
 src/aevol_create.cpp                   |  2 +-
 src/libaevol/Dump.cpp                  |  2 +-
 src/libaevol/ExpManager.cpp            | 39 +++++++++-------
 src/libaevol/Individual.cpp            |  1 -
 src/libaevol/LightTree.cpp             |  3 +-
 src/libaevol/LightTree.h               |  2 +-
 src/libaevol/OutputManager.cpp         |  8 ++--
 src/libaevol/SIMD_Individual.cpp       |  4 +-
 src/libaevol/Tree.cpp                  |  2 +-
 src/libaevol/World.cpp                 |  4 +-
 src/post_treatments/CMakeLists.txt     |  3 ++
 src/post_treatments/ancestor_stats.cpp |  3 --
 14 files changed, 49 insertions(+), 94 deletions(-)
 delete mode 100644 examples/basic/param.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2498d19a2..ebd530d98 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,11 +13,12 @@ add_definitions(-DVERSION="${PROJECT_VERSION}")
 set(AUTHORIZED_MTPERIOD 607 1279 2281 4253 11213 19937 44497 86243 132049 216091)
 
 
-set(with-x ON CACHE BOOL "Whether to enable graphical outputs")
+set(with-x OFF CACHE BOOL "Whether to enable graphical outputs")
 set(with-omp OFF CACHE BOOL "Whether to enable OpenMP parallelization")
 set(with-tbb OFF CACHE BOOL "Whether to enable TBB parallelization")
 set(enable-profiling OFF CACHE BOOL "Whether to enable profiling")
 set(with-tracing OFF CACHE BOOL "Whether to use tracing")
+set(enable-perflog OFF CACHE BOOL "Whether to active performance log")
 set(enable-normalized-fitness OFF CACHE BOOL "With this option, the NORMALIZED_FITNESS flag is defined, allowing a different fitness calculation")
 set(enable-mtperiod 607 CACHE STRING "Period of the Mersen Twister. Autorized values are : 607 1279 2281 4253 11213 19937 44497 86243 132049 216091")
 set(enable-trivialjumps OFF CACHE STRING "When this option is set, a trivial jump algorithm will be used instead of the polynomial-based method")
@@ -59,6 +60,12 @@ if ( ${with-tracing} )
     add_definitions(-D__TRACING__)
 endif ()
 
+if ( ${enable-perflog} )
+    add_definitions(-D__PERF_LOG__)
+endif ()
+
+
+
 if ( ${enable-normalized-fitness} )
     add_definitions(-DNORMALIZED_FITNESS)
 endif ()
diff --git a/examples/basic/param.in b/examples/basic/param.in
deleted file mode 100644
index dd7d25aba..000000000
--- a/examples/basic/param.in
+++ /dev/null
@@ -1,61 +0,0 @@
-###################################
-#         AEVOL PARAMATERS        #
-###################################
-
-##### 1. Initial setup ############
-STRAIN_NAME             basic_example
-SEED                    7250909
-INIT_POP_SIZE           1024
-WORLD_SIZE              32 32
-INIT_METHOD             ONE_GOOD_GENE CLONE
-CHROMOSOME_INITIAL_LENGTH   5000
-FUZZY_FLAVOR   1
-
-##### 2. Selection ################
-SELECTION_SCHEME        fitness_proportionate   1000
-
-##### 3. Mutation rates ###########
-POINT_MUTATION_RATE     1e-6
-SMALL_INSERTION_RATE    1e-6
-SMALL_DELETION_RATE     1e-6
-MAX_INDEL_SIZE          6
-
-##### 4. Rearrangement rates (w/o alignements)
-WITH_ALIGNMENTS         false
-DUPLICATION_RATE        1e-5
-DELETION_RATE           1e-5
-TRANSLOCATION_RATE      1e-5
-INVERSION_RATE          1e-5
-
-
-##### 5. Population Structure #####
-
-
-##### 6. Target function ##########
-ENV_SAMPLING      300
-ENV_ADD_GAUSSIAN  1.2   0.52  0.12
-ENV_ADD_GAUSSIAN -1.4   0.5   0.07
-ENV_ADD_GAUSSIAN  0.3   0.8   0.03
-MAX_TRIANGLE_WIDTH      0.033333333
-
-##### 7. Recording ################
-BACKUP_STEP             100
-RECORD_TREE             false
-MORE_STATS              false
-
-
-##### 8. Environment variation ####
-ENV_VARIATION           none
-
-##### 9. Phenotypic axis ##########
-ENV_AXIS_FEATURES       METABOLISM
-
-##### 10. Secretion ###############
-
-##### 11. Plasmids ################
-ALLOW_PLASMIDS              false
-WITH_TRANSFER               false
-
-
-
-
diff --git a/src/aevol_create.cpp b/src/aevol_create.cpp
index 6e4aa1647..89af64d0a 100644
--- a/src/aevol_create.cpp
+++ b/src/aevol_create.cpp
@@ -151,7 +151,7 @@ int main(int argc, char* argv[]) {
 
 
   // 8) Save the experiment
-  exp_manager->Save();
+  exp_manager->Save(true);
 
   delete exp_manager;
 }
diff --git a/src/libaevol/Dump.cpp b/src/libaevol/Dump.cpp
index 51db080be..9779acb59 100644
--- a/src/libaevol/Dump.cpp
+++ b/src/libaevol/Dump.cpp
@@ -218,7 +218,7 @@ void Dump::write_individual_probes()
   {
     for(int16_t y = 0 ; y < exp_m_->grid_height() ; y++)
     {
-      fprintf(current_file, "%" PRId32,
+      fprintf(current_file, "%llu",
           exp_m_->world()->indiv_at(x,y)->id());
       int32_t* int_probes =
           exp_m_->world()->indiv_at(x,y)->int_probes();
diff --git a/src/libaevol/ExpManager.cpp b/src/libaevol/ExpManager.cpp
index facf4a555..c31673c01 100644
--- a/src/libaevol/ExpManager.cpp
+++ b/src/libaevol/ExpManager.cpp
@@ -321,10 +321,11 @@ void ExpManager::step_to_next_generation() {
 
   //if (AeTime::time() == 14) {
     // Create the corresponding new generation
-
+#ifdef __PERF_LOG__
 auto     t1 = high_resolution_clock::now();
 
   auto     s_t1 = high_resolution_clock::now();
+#endif
 
 #ifdef __CUDACC__
   if (first_gen) {
@@ -366,7 +367,9 @@ auto     t1 = high_resolution_clock::now();
   }*/
 
   //}
-  t1 = high_resolution_clock::now();
+#ifdef __PERF_LOG__
+    t1 = high_resolution_clock::now();
+#endif
 
   if (!simd_individual->standalone())
     exp_s_->step_to_next_generation();
@@ -375,12 +378,16 @@ auto     t1 = high_resolution_clock::now();
 #ifdef __CUDACC__
   t2 = high_resolution_clock::now();
 #else
+#ifdef __PERF_LOG__
   auto t2 = high_resolution_clock::now();
 #endif
+#endif
 
-  auto duration_2 = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count();
+#ifdef __PERF_LOG__
+    auto duration_2 = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count();
 
   auto ta = high_resolution_clock::now();
+#endif
 
 /*  if (simd_first) {
     //simd_individual->check_result();
@@ -388,28 +395,26 @@ auto     t1 = high_resolution_clock::now();
   if (simd_individual->standalone())
     simd_individual->run_a_step(best_indiv()->w_max(),selection_pressure(),true);
   //}
-  auto tb = high_resolution_clock::now();
-
-
 
+#ifdef __PERF_LOG__
+  auto tb = high_resolution_clock::now();
   auto duration_simd = std::chrono::duration_cast<std::chrono::microseconds>( tb - ta ).count();
-
-
-
-
-
-
-
+#endif
 
   if (!simd_individual->standalone()) {
-    t1 = high_resolution_clock::now();
+#ifdef __PERF_LOG__
+      t1 = high_resolution_clock::now();
+#endif
     // Write statistical data and store phylogenetic data (tree)
 #pragma omp single
     {
       output_m_->write_current_generation_outputs();
     }
-    t2 = high_resolution_clock::now();
+
+#ifdef __PERF_LOG__
+      t2 = high_resolution_clock::now();
     duration_2 += std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count();
+#endif
   }
 
 #ifdef __CUDACC__
@@ -420,8 +425,12 @@ auto     t1 = high_resolution_clock::now();
     first_gen = false;
   }
 #else
+
+#ifdef __PERF_LOG__
   std::cout<<"PERFLOG,"<<AeTime::time()<<","<<duration_2<<","<<duration_simd<<std::endl;
 #endif
+
+#endif
 }
 
 /*!
diff --git a/src/libaevol/Individual.cpp b/src/libaevol/Individual.cpp
index e8dda27af..9f9ae3935 100644
--- a/src/libaevol/Individual.cpp
+++ b/src/libaevol/Individual.cpp
@@ -641,7 +641,6 @@ double Individual::dist_to_target_by_feature(
 
 /// TODO
 double Individual::fitness() const {
-  if (!fitness_computed_) printf("Error !!! %d\n",id_);
   assert(fitness_computed_);
 
   return fitness_;
diff --git a/src/libaevol/LightTree.cpp b/src/libaevol/LightTree.cpp
index 88e79fe4f..e2e4854b5 100644
--- a/src/libaevol/LightTree.cpp
+++ b/src/libaevol/LightTree.cpp
@@ -114,7 +114,7 @@ void LightTree::init_tree(int64_t time, std::list<Individual*> root_indiv) {
   }
 }
 
-void LightTree::update_tree(int64_t gen, Internal_SIMD_Struct* simd_indiv){
+void LightTree::update_tree(int64_t gen, Internal_SIMD_Struct** prev_internal_simd_struct){
   parentsNodes_.clear();
   // debug std::cout << "New generation : " << gen << '\n';
   std::unordered_map<int32_t, Node*> previous = allNodes_[gen-1];
@@ -138,6 +138,7 @@ void LightTree::update_tree(int64_t gen, Internal_SIMD_Struct* simd_indiv){
       if(prev_mrca == 0) {
           Individual* to_set;
           if (SIMD_Individual::standalone_simd) {
+            Internal_SIMD_Struct* simd_indiv = prev_internal_simd_struct[allNodes_[0].begin()->second->id_];
               int x = simd_indiv->indiv_id / exp_m_->world()->height();
               int y = simd_indiv->indiv_id % exp_m_->world()->height();
 
diff --git a/src/libaevol/LightTree.h b/src/libaevol/LightTree.h
index 803748038..0d3c02e5b 100644
--- a/src/libaevol/LightTree.h
+++ b/src/libaevol/LightTree.h
@@ -106,7 +106,7 @@ class LightTree : public Observer
     // by creating the link parent/children
     // it also prune the tree
     // if ask it perform ancestor_stat
-    void update_tree(int64_t gen, Internal_SIMD_Struct* simd_indiv = nullptr);
+    void update_tree(int64_t gen, Internal_SIMD_Struct** prev_internal_simd_struct = nullptr);
 
     // write the Newick format tree
     void write_tree(int64_t t = -1);
diff --git a/src/libaevol/OutputManager.cpp b/src/libaevol/OutputManager.cpp
index 0fce5756c..e3d0033dd 100644
--- a/src/libaevol/OutputManager.cpp
+++ b/src/libaevol/OutputManager.cpp
@@ -220,7 +220,7 @@ void OutputManager::write_current_generation_outputs(bool create) const
   stats_->add_indivs(AeTime::time(), indivs);
 
   SaveWorld* backup_world;
-  JumpingMT* backup_prng;
+  //JumpingMT* backup_prng;
   if (t % backup_step_ == 0) {
     backup_world = exp_m_->world()->make_save(exp_m_, indivs);
   }
@@ -232,7 +232,7 @@ void OutputManager::write_current_generation_outputs(bool create) const
   if (record_light_tree_ && t > 0) {
     light_tree_->update_tree(t, nullptr);
     if(t % backup_step_ == 0) {
-      std::cout << "writing light tree for gen : " << t << '\n';
+      //std::cout << "writing light tree for gen : " << t << '\n';
       write_light_tree(t);
     }
   }
@@ -249,7 +249,7 @@ void OutputManager::write_current_generation_outputs(bool create) const
   if (record_tree_ &&
       t > 0 &&
       (t % tree_->tree_step() == 0)) {
-    std::cout << "writing tree for gen : " << t << '\n';
+    //std::cout << "writing tree for gen : " << t << '\n';
     write_tree(t);
   }
 
@@ -275,7 +275,7 @@ void OutputManager::write_current_generation_outputs(bool create) const
     exp_m_->WriteDynamicFiles(t, backup_world, create);
 
     WriteLastGenerFile(".", t);
-    delete backup_prng;
+    //delete backup_prng;
     delete backup_world;
   }
 #ifdef __OPENMP_TASK
diff --git a/src/libaevol/SIMD_Individual.cpp b/src/libaevol/SIMD_Individual.cpp
index 858a32d50..32a89bf08 100644
--- a/src/libaevol/SIMD_Individual.cpp
+++ b/src/libaevol/SIMD_Individual.cpp
@@ -4672,7 +4672,7 @@ void SIMD_Individual::run_a_step(double w_max, double selection_pressure,bool op
         }
 
         if (standalone_ && exp_m_->record_light_tree() && AeTime::time() > 0) {
-            exp_m_->output_m()->light_tree()->update_tree(AeTime::time(), nullptr);
+            exp_m_->output_m()->light_tree()->update_tree(AeTime::time(), prev_internal_simd_struct);
 
             if (AeTime::time() % exp_m_->backup_step() == 0) {
                 std::cout << "writing light tree for gen : " << AeTime::time() << '\n';
@@ -4806,7 +4806,7 @@ void SIMD_Individual::check_dna() {
       if (exp_m_->world()->grid(x, y)->individual()->genetic_unit(
           0).dna()->data()[dna_pos] != internal_simd_struct[i]->dna_->data_[dna_pos]) {
 
-        printf("Check DNA indiv %d %ld %ld --- NB Mutation %ld\n",i,dna_size[i],exp_m_->world()->grid(x, y)->individual()->genetic_unit(
+        printf("Check DNA indiv %d %d %d --- NB Mutation %ld\n",i,dna_size[i],exp_m_->world()->grid(x, y)->individual()->genetic_unit(
             0).dna()->length(),exp_m_->dna_mutator_array_[i]->mutation_list_.size());
 
         printf("Divergence between classic DNA and SIMD DNA %d %d at pos %d\n",
diff --git a/src/libaevol/Tree.cpp b/src/libaevol/Tree.cpp
index 140808243..1713c203b 100644
--- a/src/libaevol/Tree.cpp
+++ b/src/libaevol/Tree.cpp
@@ -187,7 +187,7 @@ void Tree::signal_end_of_generation() {
 
     void Tree::write_to_tree_file(int64_t gen, gzFile tree_file) {
       // Write the tree in the backup
-      std::cout << "writing tree from : " << replics_.begin()->first << " to " << gen << '\n';
+      //std::cout << "writing tree from : " << replics_.begin()->first << " to " << gen << '\n';
       for (int64_t t = replics_.begin()->first ; t <= gen ; t++) {
         for (int32_t indiv_i = 0 ; indiv_i < exp_m_->nb_indivs() ; indiv_i++) {
           assert(replics_[t][indiv_i] != NULL);
diff --git a/src/libaevol/World.cpp b/src/libaevol/World.cpp
index 6bb6407e6..36708a3c8 100644
--- a/src/libaevol/World.cpp
+++ b/src/libaevol/World.cpp
@@ -72,7 +72,7 @@ namespace aevol {
 // =================================================================
 World::~World()
 {
-  for (int16_t x = 0 ; x < width_ ; x++)
+/*  for (int16_t x = 0 ; x < width_ ; x++)
     for (int16_t y = 0 ; y < height_ ; y++) {
       for (int16_t x2 = x ; x2 < width_ ; x2++)
         for (int16_t y2 = 0 ; y2 < height_ ; y2++) {
@@ -80,7 +80,7 @@ World::~World()
           if (grid_[x][y]->individual_->id() == grid_[x2][y2]->individual_->id())
             grid_[x2][y2]->individual_ = nullptr;
     }
-  }
+  }*/
 
   for (int16_t x = 0 ; x < width_ ; x++)
     for (int16_t y = 0 ; y < height_ ; y++)
diff --git a/src/post_treatments/CMakeLists.txt b/src/post_treatments/CMakeLists.txt
index 70f9cbd19..0d6df0b4d 100644
--- a/src/post_treatments/CMakeLists.txt
+++ b/src/post_treatments/CMakeLists.txt
@@ -45,6 +45,9 @@ target_link_libraries(aevol_misc_lineage PUBLIC aevol)
 add_executable(aevol_misc_mutagenesis mutagenesis.cpp)
 target_link_libraries(aevol_misc_mutagenesis PUBLIC aevol)
 
+add_executable(aevol_misc_soft_lineage soft_lineage.cpp)
+target_link_libraries(aevol_misc_soft_lineage PUBLIC aevol)
+
 add_executable(aevol_misc_robustness robustness.cpp IndivAnalysis.cpp)
 target_link_libraries(aevol_misc_robustness PUBLIC aevol)
 
diff --git a/src/post_treatments/ancestor_stats.cpp b/src/post_treatments/ancestor_stats.cpp
index d80a6f813..12cad904f 100644
--- a/src/post_treatments/ancestor_stats.cpp
+++ b/src/post_treatments/ancestor_stats.cpp
@@ -482,9 +482,6 @@ int main(int argc, char* argv[]) {
         composed_fitness/=number_of_phenotypic_target_models;
         fitmeta<<t0<<","<<"-1"<<","<<"1"<<","<<composed_fitness<<std::endl;
     }
-#else
-    printf("Fitness local sum is not supported for Aevol (only R-Aevol)\n");
-    exit(-1);
 #endif
 
     indiv->Reevaluate();
-- 
GitLab