2

I have been trying to parallelize an optimization algorithm written in FORTRAN90 and compiled / run using the cygwin interface with gfortran XXXXX -fomp.

The algorithm computes a gradient and hessian matrix by finite differences from a subroutine call. The subroutine is pretty large and involves manipulation of an ~2 mb matrix each time. For the purpose of discussion I'll use "call srtin()" as example of the subroutine call.

Without using any OMP code anywhere in the compile, the program fails if I use the -fomp option during compilation (the code compiles without a hitch). Regular compilation and execution using gfortran does not cause any issues. However, the moment I add the -fomp option, the resulting executable causes a segmentation fault if a single call to srtin() is present.

I've read on this site that a common issue with omp is stacksize issues. I've inferred (possibly wrong) that the master thread stack size issue is at fault because I haven't yet included any code that would create any slave threads. On a typical linux computer, my understanding is, that I would use the " ulimit -s XXX" to reset this stacksize to a sufficiently high value so that the error no longer occurs. I've tried this through my cygwin interface, but the error persists. I've also tried using the peflags command to set a higher stack memory for this executable with no success. I also have increased the OMP_STACKSIZE environmental variable with no success.

Does anyone have any suggestions?

FooAnon
  • 566
  • 1
  • 4
  • 11
  • I do use -Wl,--stack,900000000 in the cygwin64 gfortran link step for -fopenmp to avoid failure due to insufficient primary stack size. I think OMP_STACKSIZE environment variable is supported, although I've not seen documented which environment variables are supported by libgfortran on Windows. I don't know how much stack can be supported by 32-bit cygwin gfortran; I suspect it's much less. – tim18 Jul 12 '17 at 01:32

1 Answers1

1

Enabling OpenMP in GCC disables the automatic placement of large arrays on the heap. Thus, it could make your program crash even if there are no OpenMP constructs in the code. Windows has no equivalent of ulimit -s as the stack size of the main thread is read from the PE header of the executable file. OMP_STACKSIZE controls the stack size of the worker threads and does not affect the one of the master thread.

Use -Wl,--stack,some_big_value as advised by @tim18 instead of editing the PE header with peflags. some_big_value is in bytes. See here for more information.

Hristo Iliev
  • 72,659
  • 12
  • 135
  • 186