|
[Sponsors] |
March 24, 2018, 21:42 |
C++ Memory Management
|
#1 |
New Member
Join Date: Oct 2017
Posts: 7
Rep Power: 8 |
Dear CFD friends!
I am writing a CFD code solving 3D Euler equations (compressible, inviscid flow). The first problem is, I am not allowed to generate a big matrix to store the conserved variables, if I am having a 1000x1000x1000 Cartesian structured mesh. Here is what I have tried. (1) Using "new" to generate a dynamic array; new.JPG (2) Using "vector" to generate a dynamic array; vector.JPG (3) Generating a static array variable. static.JPG But none of them worked. It makes me think that it is necessary that I change the data structure/organization. But anyway I need a matrix like this to store the conserved variables at each time step. Any idea will be much appreciated!!! N. Si |
|
March 25, 2018, 03:19 |
|
#2 |
New Member
John Peralta
Join Date: Mar 2018
Location: Paris
Posts: 2
Rep Power: 0 |
Have you calculated the required RAM to store an array of this size?
|
|
March 25, 2018, 07:50 |
|
#3 |
Super Moderator
|
All of the methods you tried are bad ways to use multi-d array in c/c++.
One way is to store it as a one-d array and wrap the indexing (I haven't checked the index wrapping, but you see the general idea) Code:
#include<iostream> #define u(i,j,k) u_[(i) + (j)*imax + (k)*imax*jmax] using namespace std; int main() { const int imax = 1000; const int jmax = 1000; const int kmax = 1000; double* u_ = new double[imax*jmax*kmax]; u(0,0,0) = 100.0; cout << u(0,0,0) << endl; } Code:
#include<iostream> using namespace std; int main() { const int imax = 1000; const int jmax = 1000; const int kmax = 1000; double (*u)[jmax][kmax]; u = new double[imax][jmax][kmax]; u[0][0][0] = 100.0; cout << u[0][0][0] << endl; } |
|
March 27, 2018, 10:03 |
|
#4 |
New Member
Biswajit Ghosh
Join Date: Oct 2014
Location: Durgapur, India
Posts: 21
Rep Power: 11 |
Using vector is a good option. Additionally I would say, as you are into scientific computing, consider using some reliable array library. I personally like blitz++
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Lenovo C30 memory configuration and discussions with Lenovo | matthewe | Hardware | 3 | October 17, 2013 10:23 |
Memory management incongruence | Flavio | CFX | 5 | November 1, 2006 12:18 |
CFX CPU time & real time | Nick Strantzias | CFX | 8 | July 23, 2006 17:50 |
memory management under unix system | nicolas | Siemens | 22 | January 30, 2006 22:40 |
memory management! | Tingguang Ma | Main CFD Forum | 3 | October 25, 2000 08:35 |