Runtime crash with -O0
| Bugzilla Link | 26540 |
| Resolution | FIXED |
| Resolved on | Jun 06, 2019 02:53 |
| Version | unspecified |
| OS | Linux |
| Attachments | Testcase |
| CC | @alexey-bataev,@AndreyChurbanov,@hahnjo,@hfinkel,@jpeyton52 |
| Fixed by commit(s) | r362618 |
Extended Description
The attached code when compiled with -O0 will fail at runtime:
clang++ -Wno-c++11-narrowing -fopenmp -O0 smallpt.cpp ./a.out 100 Rendering (100 spp) 20.47%[1] 23947 segmentation fault (core dumped) ./a.out 100
Admittedly the code is very ugly but libgomp seems to work so might be an interesting testcase.
Fixed by commit r362618.
Confirmed, thank you!
Fixed by commit r362618.
@Intel is this worth implementing?
It looks harmless, and not of high priority (because of easy workaround). So, would be good to have it implemented. Might help some users to reduce number of environment variables to set.
@Intel is this worth implementing?
Done
Well I expected compatibility with libgomp would be nice, but in the end you are right.
It would.
Feel free to close the bug as invalid or similar.
I suggest we change this to "Priority: Enhancement", so we don't forget about it, but also don't cause it to be blocking anything. (Alexey, since you own it, maybe you should do that?)
So, to resolve this bug your suggestion:
So the only time when this might make sense is if
- The user hasn't said anything
- The initial stack has a finite size
makes the most sense.
Yes, except that I don't really think it's a bug at all.
I agree that it would be friendly to adopt the behaviour you cite, and that may help some people, but, really, the user needs to set an appropriate stacksize for their parallel code just as they do for their serial codes. If they don't, then the code may crash, but that's not due to a bug in the runtime any more than a process exiting because it's used up a CPU limit is a bug in the runtime. Fundamentally, if the user doesn't ask for enough resources to run their code, then it'll fail to run.
Well I expected compatibility with libgomp would be nice, but in the end you are right. Feel free to close the bug as invalid or similar.
So, to resolve this bug your suggestion:
So the only time when this might make sense is if
- The user hasn't said anything
- The initial stack has a finite size
makes the most sense.
Yes, except that I don't really think it's a bug at all.
I agree that it would be friendly to adopt the behaviour you cite, and that may help some people, but, really, the user needs to set an appropriate stacksize for their parallel code just as they do for their serial codes. If they don't, then the code may crash, but that's not due to a bug in the runtime any more than a process exiting because it's used up a CPU limit is a bug in the runtime. Fundamentally, if the user doesn't ask for enough resources to run their code, then it'll fail to run.
- What do you do if the default stack is "unlimited"?
Then that's what the user wants.
They may want it, but it's not sanely implementable :-)
For the initial thread, the OS places the stack at a high address, and it grows downwards (at least on X86). Since most of the other things in the address space are at much lower addresses it has a lot of VA space into which to grow, and the kernel treats mappings with the stack bit set as being able to grow downwards. But for thread stacks you can't place 64 of them all at the top, because there's only one top! So, you'd have to explicitly scatter them through the address space, but the OpenMP runtime can't control where the kernel is going to place other stuff (like shared libraries, or heap space) so to guarantee any size for a stack the runtime has to explicitly allocate it, at which point you need to know what that size is, and it's not "unlimited".
So, to resolve this bug your suggestion:
So the only time when this might make sense is if
- The user hasn't said anything
- The initial stack has a finite size
makes the most sense.
- What do you do if the default stack is "unlimited"?
Then that's what the user wants.
They may want it, but it's not sanely implementable :-)
For the initial thread, the OS places the stack at a high address, and it grows downwards (at least on X86). Since most of the other things in the address space are at much lower addresses it has a lot of VA space into which to grow, and the kernel treats mappings with the stack bit set as being able to grow downwards. But for thread stacks you can't place 64 of them all at the top, because there's only one top! So, you'd have to explicitly scatter them through the address space, but the OpenMP runtime can't control where the kernel is going to place other stuff (like shared libraries, or heap space) so to guarantee any size for a stack the runtime has to explicitly allocate it, at which point you need to know what that size is, and it's not "unlimited".
As I suspected libgomp is using the system's default stack size retrieved via pthread_attr_getstacksize function. It would make sense for libiomp to do the same at least on Linux.
It's not immediately obvious that that is the right thing to do.
- OpenMP specifically allows the user to set the stack size by use of the OMP_STACKSIZE environment variable. This is part of the standard, not an implementation specific tweak.
libgomp lets you override stack size via OMP_STACKSIZE so that's not a problem.
- What do you do if the default stack is "unlimited"?
Then that's what the user wants.
- In many codes the user may not need as large a stack in the worker threads as they do in the initial one. (Though I suppose this only allocates address-space, not physical memory).
So the only time when this might make sense is if
- The user hasn't said anything
Yes.
- The initial stack has a finite size
Well, yes.
I guess that may still be worth doing, but it's not a panacea for all stack size problems!
Indeed and I'll admit this is not a real life test case.
Thanks!
As I suspected libgomp is using the system's default stack size retrieved via pthread_attr_getstacksize function. It would make sense for libiomp to do the same at least on Linux.
It's not immediately obvious that that is the right thing to do.
-
OpenMP specifically allows the user to set the stack size by use of the OMP_STACKSIZE environment variable. This is part of the standard, not an implementation specific tweak.
-
What do you do if the default stack is "unlimited"?
-
In many codes the user may not need as large a stack in the worker threads as they do in the initial one. (Though I suppose this only allocates address-space, not physical memory).
So the only time when this might make sense is if
- The user hasn't said anything
- The initial stack has a finite size
I guess that may still be worth doing, but it's not a panacea for all stack size problems!
Looks like this test case needs some stack size for OpenMP worker threads, and the default value of 4MB (on Linux 64-bit) is not enough. Try to set bigger stack size by setting environment variable KMP_STACKSIZE to 8M or bigger. The 8M works for me running with parameter 1000.
I don't know how much stack size libgomp gives its worker threads, probably more than libomp.
Indeed I wonder if libgomp uses the default stack size of the system:
λ ulimit -s 8192
which shows 8MB of default stack.
As I suspected libgomp is using the system's default stack size retrieved via pthread_attr_getstacksize function. It would make sense for libiomp to do the same at least on Linux.
Looks like this test case needs some stack size for OpenMP worker threads, and the default value of 4MB (on Linux 64-bit) is not enough. Try to set bigger stack size by setting environment variable KMP_STACKSIZE to 8M or bigger. The 8M works for me running with parameter 1000.
I don't know how much stack size libgomp gives its worker threads, probably more than libomp.
Indeed I wonder if libgomp uses the default stack size of the system:
λ ulimit -s 8192
which shows 8MB of default stack.
Looks like this test case needs some stack size for OpenMP worker threads, and the default value of 4MB (on Linux 64-bit) is not enough. Try to set bigger stack size by setting environment variable KMP_STACKSIZE to 8M or bigger. The 8M works for me running with parameter 1000.
I don't know how much stack size libgomp gives its worker threads, probably more than libomp.
Hi, could you provide more details about system, environment etc.? Tried to reproduce on MacOS 10.11 and Linux x86_64 with no luck, the code works without any crashes
This is on Linux x86-64 with kernel v4.4.0, just make sure you run the executable with a number >= 100
such as
./a.out 100
if you still can't produce try a higher number like 1000.
Ahh, missed that. Yes, I see a crash.
Hi, could you provide more details about system, environment etc.? Tried to reproduce on MacOS 10.11 and Linux x86_64 with no luck, the code works without any crashes
This is on Linux x86-64 with kernel v4.4.0, just make sure you run the executable with a number >= 100
such as
./a.out 100
if you still can't produce try a higher number like 1000.
Hi, could you provide more details about system, environment etc.? Tried to reproduce on MacOS 10.11 and Linux x86_64 with no luck, the code works without any crashes
assigned to @AndreyChurbanov