我收到一个奇怪的错误:
*** glibc detected *** findbasis: free(): invalid next size (normal): 0x0000000006a32ce0 ***
当我尝试关闭()一个标准::流:
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;
}
运行时,此程序永远不会到达"done2"(或"错误或失败..."),但是达到"done1"。 此外,写出的数据很好(正如我所期望的那样)。
老实说,我不知道为什么会发生这种情况,我想不出"close()"会失败的任何原因。
感谢您的任何帮助。
(我开始认为这是某种编译器错误/错误。 我正在运行 GCC 4.1.2 (!(我相信RHEL 5)通过mpicxx)
glibc 错误听起来像是释放内存有问题。如果你在Valgrind(一个免费的内存分析器)中运行,它应该会给你一个更有用的错误解释。
在 Valgrind 中运行是相当轻松的 - 只需使用 -g 选项编译可执行文件以添加调试标志(假设您使用的是 GNU 编译器),然后在 Linux 终端中输入 valgrind ./your_executable
看看会发生什么。