From 99119e5f455cd5e8ee663b9dc26cc3add8e86292 Mon Sep 17 00:00:00 2001
From: Ben Cumming <bcumming@cscs.ch>
Date: Tue, 23 Aug 2016 10:35:21 +0200
Subject: [PATCH] fix issues with Intel Compiler and optimized builds

* replace a call to `std::iota` with a for loop because the Intel
compiler was optimizing out the `std::iota` call in a unit test.
* add uniform syntax for converting pointer+size and ArrayView+size
into an ArrayView to provide uniform method for accessing ranges
inside mechanisms with/without optimizations.
---
 external/vector                |  2 +-
 tests/unit/test_algorithms.cpp |  7 +++++--
 tests/unit/test_synapses.cpp   | 33 ++++++++++++++++++++-------------
 3 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/external/vector b/external/vector
index 8284611f..c8678e80 160000
--- a/external/vector
+++ b/external/vector
@@ -1 +1 @@
-Subproject commit 8284611f05b0fbe21a1f84630e2726015cb1d96d
+Subproject commit c8678e80660cd63b293ade80ece8eed2249c1b06
diff --git a/tests/unit/test_algorithms.cpp b/tests/unit/test_algorithms.cpp
index 2e82bcc9..b371b9d6 100644
--- a/tests/unit/test_algorithms.cpp
+++ b/tests/unit/test_algorithms.cpp
@@ -14,9 +14,12 @@ TEST(algorithms, sum)
     EXPECT_EQ(10*2, nest::mc::algorithms::sum(v1));
 
     // make an array 1:20 and sum it up using formula for arithmetic sequence
-    std::vector<int> v2(20);
-    std::iota(v2.begin(), v2.end(), 1);
     auto n = 20;
+    std::vector<int> v2(n);
+    // can't use iota because the Intel compiler optimizes it out, despite
+    // the result being required in EXPECT_EQ
+    // std::iota(v2.begin(), v2.end(), 1);
+    for(auto i=0; i<n; ++i) { v2[i] = i+1; }
     EXPECT_EQ((n+1)*n/2, nest::mc::algorithms::sum(v2));
 }
 
diff --git a/tests/unit/test_synapses.cpp b/tests/unit/test_synapses.cpp
index 8cd9de04..357a5a2a 100644
--- a/tests/unit/test_synapses.cpp
+++ b/tests/unit/test_synapses.cpp
@@ -58,30 +58,33 @@ TEST(synapses, expsyn_basic_state)
 
     auto ptr = dynamic_cast<synapse_type*>(mech.get());
 
+    auto n = ptr->size();
+    using view = synapse_type::view_type;
+
     // parameters initialized to default values
-    for(auto e : ptr->e) {
+    for(auto e : view(ptr->e, n)) {
         EXPECT_EQ(e, 0.);
     }
-    for(auto tau : ptr->tau) {
+    for(auto tau : view(ptr->tau, n)) {
         EXPECT_EQ(tau, 2.0);
     }
 
     // current and voltage vectors correctly hooked up
-    for(auto v : ptr->vec_v_) {
+    for(auto v : view(ptr->vec_v_, n)) {
         EXPECT_EQ(v, -65.);
     }
-    for(auto i : ptr->vec_i_) {
+    for(auto i : view(ptr->vec_i_, n)) {
         EXPECT_EQ(i, 1.0);
     }
 
     // should be initialized to NaN
-    for(auto g : ptr->g) {
+    for(auto g : view(ptr->g, n)) {
         EXPECT_NE(g, g);
     }
 
     // initialize state then check g has been set to zero
     ptr->nrn_init();
-    for(auto g : ptr->g) {
+    for(auto g : view(ptr->g, n)) {
         EXPECT_EQ(g, 0.);
     }
 
@@ -106,32 +109,35 @@ TEST(synapses, exp2syn_basic_state)
 
     auto ptr = dynamic_cast<synapse_type*>(mech.get());
 
+    auto n = ptr->size();
+    using view = synapse_type::view_type;
+
     // parameters initialized to default values
-    for(auto e : ptr->e) {
+    for(auto e : view(ptr->e, n)) {
         EXPECT_EQ(e, 0.);
     }
-    for(auto tau1: ptr->tau1) {
+    for(auto tau1: view(ptr->tau1, n)) {
         EXPECT_EQ(tau1, 0.5);
     }
-    for(auto tau2: ptr->tau2) {
+    for(auto tau2: view(ptr->tau2, n)) {
         EXPECT_EQ(tau2, 2.0);
     }
 
     // should be initialized to NaN
-    for(auto factor: ptr->factor) {
+    for(auto factor: view(ptr->factor, n)) {
         EXPECT_NE(factor, factor);
     }
 
     // initialize state then check factor has sane (positive) value
     // and A and B are zero
     ptr->nrn_init();
-    for(auto factor: ptr->factor) {
+    for(auto factor: view(ptr->factor, n)) {
         EXPECT_GT(factor, 0.);
     }
-    for(auto A: ptr->A) {
+    for(auto A: view(ptr->A, n)) {
         EXPECT_EQ(A, 0.);
     }
-    for(auto B: ptr->B) {
+    for(auto B: view(ptr->B, n)) {
         EXPECT_EQ(B, 0.);
     }
 
@@ -142,3 +148,4 @@ TEST(synapses, exp2syn_basic_state)
     EXPECT_NEAR(ptr->A[1], ptr->factor[1]*3.14, 1e-6);
     EXPECT_NEAR(ptr->B[3], ptr->factor[3]*1.04, 1e-6);
 }
+
-- 
GitLab