|
[Sponsors] |
One dimensional array in OF21(Segmentation fault (core dumped)) |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
December 21, 2022, 15:03 |
One dimensional array in OF21(Segmentation fault (core dumped))
|
#1 |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 206
Rep Power: 8 |
Hello all
I am defining a one dimensional parameter which has 2 million elements; Code:
int nCounter = U.size(); Info << "1" << endl; scalar AAAA[nCounter]; for(int i=0; i<nCounter; i++) { AAAA[i] = 0;} Code:
1 Segmentation fault (core dumped) |
|
December 21, 2022, 20:45 |
|
#2 | |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 206
Rep Power: 8 |
I afraid that maybe i counter goes beyond the limits so I change it to
Code:
for(int i=1 i<100; i++) { AAAA[i] = 0;} Thanks, Farzad Quote:
|
||
December 22, 2022, 06:00 |
|
#3 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
I don't understand the source of your error, but there is no reason to be using raw C arrays instead of an OpenFOAM list or even a std vector. Give the following a try:
Code:
scalarField AAA(U.size()); for (label i=0; i < AAA.size(); ++i) { AAA[i] = 0; } Code:
scalarField AAA(U.size(), Zero); |
|
December 22, 2022, 14:22 |
|
#4 | |
Senior Member
Farzad Faraji
Join Date: Nov 2019
Posts: 206
Rep Power: 8 |
Thanks a lot for your advice. I did it like this as you said and it works;
Code:
int nCounter = U.size(); scalarField AAA(nCounter); and since I need it to set zero every time step, I set it zero like this every time step; Code:
for(int i=0; i<nCounter; i++) {AAA[i] = 0;} Thanks, Farzad Quote:
|
||
December 23, 2022, 02:50 |
|
#5 | |
Member
Join Date: Jan 2022
Location: Germany
Posts: 72
Rep Power: 4 |
Quote:
You can either use the vectorized method to make the for loop obsolete (but I think the compiler automatically using SIMD and might be that an overloaded operator[] will prohibit this operation) or I know for the GeometricField<T> class there is an overloaded operator= which sets the whole Field with a particular value. Since GeometricField is inhereting from Field class (if you go for Field<scalar>) I think there should be something similiar Code:
AAA[:] = 0 //vectorized // works at least for GeometricField<T> AAA = dimensionedScalar(dimless, 0.0) //sets .ref and .boundaryFieldRed to 0 |
||
Tags |
array, error, fault, of21, segmentation |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[OpenFOAM] Paraview segmentation fault core dumped | GLfast80 | ParaView | 0 | March 13, 2021 13:53 |
Segmentation fault (core dumped) | prashantgoel | CONVERGE | 2 | May 26, 2020 13:48 |
SU2-7.0.1 on ubuntu 18.04 | hyunko | SU2 Installation | 7 | March 16, 2020 05:37 |
Segmentation fault (core dumped) | Sugajen | OpenFOAM Running, Solving & CFD | 1 | August 2, 2017 13:06 |
solving a conduction problem in FLUENT using UDF | Avin2407 | Fluent UDF and Scheme Programming | 1 | March 13, 2015 03:02 |