Nested loop that modifies 3D array in C++ not working

Viewed 23

I'm testing the performance of C++ when modifying an array element by element:

#include <chrono>
#include <iostream>

using namespace std;

int main() {
  cout << "Hello" << std::endl;
  const int N = 64;
  double F[N][N][N];

  chrono::steady_clock::time_point start = chrono::steady_clock::now();
  for (int i = 1; i < N - 1; i++) {
    cout << i << std::endl;
    for (int j = 1; j < N - 1; j++) {
      for (int k = 1; k < N - 1; k++) {
        F[i][j][k] =
            std::pow(((1 / 3. - i) / (1 / 3. + i)), 2) + F[i - 1][j][k + 1];
      }
    }
  }
  chrono::steady_clock::time_point end = chrono::steady_clock::now();

  cout << "Elapsed time is "
       << chrono::duration_cast<chrono::milliseconds>(end - start).count()
       << "[ms]" << std::endl;
}

With N <= 63 the program works but with N > 63 it stops working. When debugging and running there is no message error and I don't know what is happening.

Why is this code not working with N > 63?

0 Answers
Related