0

I am trying to initialise two 2D arrays, namely psi_0 and omega_0, with the data type as double. The sizes of the arrays are 401x401. I have written the last printing statement to check if the code is running properly or not. As soon as I initialise arrays, the last line doesn't get printed and this is getting displayed only: PS C:\Users\Avii\Desktop> cd "c:\Users\Avii\Desktop\" ; if ($?) { g++ trialc++.cpp -o trialc++ } ; if ($?) { .\trialc++ }.

Following is my code:

#include<iostream>
#include<iomanip>
#include <math.h>
#include <vector>
#include <algorithm>
#include <thread>
#include <chrono>
using namespace std;

void display(vector<double> &v){
    for (int i = 0; i < v.size(); i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
int main(){

    const int N = 401;
    const double pi = 3.141592653589793;
    double L = pi/2;
    double r = 1.5;
    //-------------------------------------------------------------------
.
..
...
    double psi_0[N][N]; 
    double omega_0[N][N];
    
    
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            psi_0[i][j] = sin(x_vec[i]) * (sin(y_vec[j]));
            omega_0[i][j]= 2 * sin(x_vec[i]) * sin(y_vec[j]);
        }
        
    }
    
    cout<< "everything is fine"; // to check if the code has run till last or not!
    
    return 0;
}

Here x_vec and y_vec are two vectors of size 401 and data type as double. I have tried using flush but could not see the problem is solved! Any help is highly appreciated!!

Avii
  • 164
  • 12
  • 1
    If you want debugging help, then please try to create a proper [mre] to show us. And catch crashes in a debugger so you can tell us where in your code it happens. – Some programmer dude Apr 19 '22 at 12:01
  • You may have a stack overflow since you are creating large arrays on the stack. – drescherjm Apr 19 '22 at 12:04
  • @Someprogrammerdude Nothing is getting printed. Only `PS C:\Users\Avii\Desktop> cd "c:\Users\Avii\Desktop\" ; if ($?) { g++ trialc++.cpp -o trialc++ } ; if ($?) { .\trialc++ }` What do you want in example to see? – Avii Apr 19 '22 at 12:07
  • 1
    The most common implementation for local variables is on the process stack. The stack is a limited resource, on Linux the default stack is 8MiB and on Windows the default size is only a single MiB. Your two arrays `psi_0` and `omeag_0` together will be almost 2.5 MiB. – Some programmer dude Apr 19 '22 at 12:07
  • @Someprogrammerdude how can we solve this?? – Avii Apr 19 '22 at 12:09
  • @drescherjm How can we solve this?? – Avii Apr 19 '22 at 12:16
  • 1
    Move `double psi_0[N][N]; double omega_0[N][N];` before main or use `std::vector` instead – drescherjm Apr 19 '22 at 12:18
  • 1
    Use `std::vector` instead? – Some programmer dude Apr 19 '22 at 12:18
  • 2
    I would recommend running your program in a debugger. then you should get more information on where the program actually crashes, and why. See [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173), and maybe [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) – codeling Apr 19 '22 at 12:22
  • 3
    VSCode should have a debugger. I think it will show you an exit code as well so that would have told you the problem after you decoded the value by copying it to this website: [https://james.darpinian.com/decoder/](https://james.darpinian.com/decoder/) – drescherjm Apr 19 '22 at 12:28

0 Answers0