This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Change from FENICS 1.4 to 1.5 - Possible problem with memory

+1 vote

Hi,
I am solving a diffusion-reaction problem using fenics. Recently I moved from 1.4 to 1.5. My code was working correctly with the older version of fenics, but not with the 1.5. A simple check revealed the source of the error came from the reaction part.
The code structure of main function:

// 1. read in meshes, define functions and do assembling. 
// ... // This part runs without giving any errors.

// 2. allocate object for reactions.
std::vector<CELL*> cells;

for ( int i = 0; i < mesh.num_vertices(); ++i )
    {
        cells.push_back( new CELL() );
    }
while(t<T) {
// run the time loop solving reaction
      for(i = 0; i<cells.size();i++)
         // error  here in fenics 1.5 but not 1.4
          cells[i]->Run();     // note -> giving errors here -> NaN error
          // checking NaNs.
          if(cells[i]->V != cells[i]->V)
              std::cerr << "NaNs" << std::endl;

      //update diffusion solution vector and solve diffusion problem. 
     t+=dt;
}

However, if I define and allocate cells vector at the very beginning of the main function, the reaction part works fine without giving NaNs.

// 1. allocate object for reactions.
std::vector<CELL*> cells;
// NUM  == mesh.num_vertices();
for ( int i = 0; i < NUM; ++i )
    {
        cells.push_back( new CELL() );
    }
// 2. read in meshes, define functions and do assembling. 
// ... // This part runs without giving any errors.

while(t<T) {
// run the time loop solving reaction
      for(i = 0; i<cells.size();i++)
          cells[i]->Run();     // note it's working now...
          // checking NaNs.
          if(cells[i]->V != cells[i]->V)
              std::cerr << "NaNs" << std::endl;

      //update diffusion solution vector and solve diffusion problem. 
     t+=dt;
}

I am wondering if this is due to memory allocating problem? Any changes on compiling options from fenics 1.4 to 1.5?

Thanks!

closed with the note: solved
asked Jun 23, 2015 by qiangzini FEniCS Novice (760 points)
closed Jun 25, 2015 by qiangzini

I find running with valgrind is useful to track down memory errors

Thanks I tried valgrind which revealed some memory issues and uninitialised values in my user defined code. Some memory issue with MPI, but considering https://www.open-mpi.org/faq/?category=debugging#valgrind_clean, this shouldn't be an issue.

Thanks.

...