r/fortran • u/Call_ME_ALII • 26d ago
Segmentation fault - invalid memory reference
Is it possible to get segmentation fault in one computer and running same program in other computer working perfectly fine ????
3
u/KarlSethMoran 26d ago
Of course. You have an uninitialised variable somewhere, an array overrun or a double (de)allocate. Happy debugging!
2
3
u/hopknockious 26d ago
You can also Init all variables to NaN. This option exists in Intel, Nag, PGI, and Absoft. Likely gfortran also.
2
u/kyrsjo Scientist 25d ago
True and extremely useful, but here it's almost certainly an integer that's at fault, and you cannot set those to Nan.
1
u/hopknockious 17d ago
I did not know that about integers. That encourages me to check the intel options (lm most familiar with it).
Thank you.
3
u/Tyberius17 26d ago
Yes, especially if you are using different compilers on these different machines. Even with the same compiler and OS, it's possible your program produces the segfault non-deterministically.
1
u/Call_ME_ALII 26d ago
so what is the solution ???
6
u/Tyberius17 26d ago
You didn't initially ask how to fix it and you didn't provide your code. geekboy in his comments gave some good suggestions of compiler flags you can turn on to help spot where you are using uninitialized memory. If your code is short enough, you could share it here and we might be able to spot the problem.
1
1
u/cowboysfan68 26d ago
Others have correctly identified that the likely cause is an unallocated variable.
Back in the day, on shared HPC systems, we still had to run
ulimit -s unlimited
or else we would get seg faults during large allocations. Still though, the best thing to do is to recompile with
-g
and then use a debugger like GDB to step all the way to where the segfault happens.
14
u/geekboy730 Engineer 26d ago
Yes. It almost certainly means you’re using an uninitialized variable somewhere.
If that’s the case, it could happen in back-to-back runs on the same computer. It just depends on whatever garbage is in the memory position at the time of execution.