# Run external fortran program encountered segmentation fault

I have a fortran program has some command line parameters.

I want to use Mathematica's Run function to realize simple parallelization to loop over a set of command line paramters.

What is more, there is a system size parameter L in my fortran program. With larger L, more memory needed.

I first done test with L=100, the mathematica script run.m is simply

Run["./a.out",0,0,0,0,0,0,0]


and math -script run.m works great.

However, if I change L=300 in fortran and recompile. math -script run.m got errors like

[q@i02n18 no_v]\$ math -script run.m
getting sparse matrix ...
getting dos by chebyshev ...
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source
a.out              00000000004D70E1  Unknown               Unknown  Unknown
a.out              00000000004D521B  Unknown               Unknown  Unknown
a.out              0000000000479AB4  Unknown               Unknown  Unknown
a.out              00000000004798C6  Unknown               Unknown  Unknown
a.out              0000000000436029  Unknown               Unknown  Unknown
a.out              0000000000439C16  Unknown               Unknown  Unknown
a.out              00000000004166F0  chebyshev_ldos_            78  module_chebyshev.f90
a.out              00000000004127D6  twoband_                  118  model_twoband.f90
a.out              0000000000411228  MAIN__                     39  main.f90
a.out              0000000000403BDE  Unknown               Unknown  Unknown
libc-2.17.so       00002AC56B720B35  __libc_start_main     Unknown  Unknown
a.out              0000000000403AE9  Unknown               Unknown  Unknown


As we can see, it did start calculation because it print two lines of message, but then subject to "segmentation fault occurred"

However, at the time, if I run ./a.out 0 0 0 0 0 0 0 in the terminal, it works, and if I look at the memory usage, it is quite small as 145MB. So it probably not due to memory issue maybe?

Is anybody know whether there is some implicit limit of Run function?

• Hi, @ilian. Could you explain it a little, why we need LD_LIBRARY_PATH? Anyway, it is seems not a convenient workaround, because my program needs other libraries error while loading shared libraries: libmkl_intel_lp64.so: cannot open shared object file: No such file or directory – matheorem Jan 22 '18 at 3:05
• You should set LD_LIBRARY_PATH to its normal value (outside Mathematica) then. The Mathematica launcher script prepends to it, so likely the crash is due to your program loading an incorrect MKL library from Mathematica's layout. – ilian Jan 22 '18 at 3:09
• @ilian I don't get it. But L=100 case is working. – matheorem Jan 22 '18 at 3:10
• @ilian No, it is not working. Still segmentation fault – matheorem Jan 22 '18 at 3:16
• @ilian The error message is the same, no matter inside or outside mma – matheorem Jan 22 '18 at 3:27