I’m getting a strange error:
*** glibc detected *** findbasis: free(): invalid next size (normal): 0x0000000006a32ce0 ***
When I try to close() a std::ofstream:
void writeEvectors(int l, parameters params, PetscReal* evectors, int basis_size)
{
for (int n = 1 + l; n <= params.nmax(); n++)
{
std::stringstream fname(std::ios::out);
fname << params.getBasisFunctionFolder() << "/evectors_n" << std::setw(4) << std::setfill('0') << n << "_l" << std::setw(3) << std::setfill('0') << l;
std::ofstream out(fname.str().c_str(), std::ios::binary);
std::cerr << "write out file:" << fname.str() << " ...";
out.write((char*)( evectors + n * basis_size),sizeof(PetscReal) * basis_size);
std::cerr << "done1" << std::endl;
if (out.fail() || out.bad())
std::cerr << "bad or fail..." << std::endl;
out.close();
std::cerr << "done2" << std::endl;
}
std::cout << "done writing out all evectors?" << std::endl;
}
When run, this program never reaches the “done2” (or the “bad or fail…”), however the “done1” is reached. Also, the data that is written out is good (as in what I expect).
I’m honestly at a loss as to why this happens, I can’t think of any reason “close()” would fail.
Thanks for any help.
(I’m beginning to think it is some sort of compiler bug/error. I’m running GCC 4.1.2 (!) (RHEL 5 I believe) through mpicxx)
The glibc error sounds like there’s a problem with freeing memory. If you run inside Valgrind, a free memory profiler, it ought to give you a more helpful explanation of the error.
Running in Valgrind is fairly painless – just compile the executable with the -g option to add debugging flags (assuming you’re using the GNU compiler) and then in your Linux terminal enter
valgrind ./your_executableand see what happens.