Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

differences between -O1 and -O2?

John_W_3
Beginner
1,270 Views

Hi,

I have a code that segfaults with -O2 but not with -O1. Is there a way I can find out what the optimization differences between O1 and O2 are so that I can get a clue about the segfault?

Thanks.

jgw

 

0 Kudos
6 Replies
Anoop_M_Intel
Employee
1,270 Views

Hi John,

We have some internal compiler options which can help with this. If you could provide me with the test case, I can help figuring out the issue.

Thanks and Regards
Anoop

0 Kudos
John_W_3
Beginner
1,270 Views

I don't have a simple test case that demonstrates the behavior. The code is foam extend 3.2 built against the SGI MPT mpi library. If you have access to such a system I can tell you how to reproduce it, but I don't have a concise listing to reproduce.

0 Kudos
TimP
Honored Contributor III
1,270 Views

O2 invokes auto-vectorization, sometimes assisted by implicit allocation of temporary array. So, stack overflow is among the usual easily remedied suspects.

0 Kudos
Anoop_M_Intel
Employee
1,270 Views

Option 1: You can try disabling vectorization using -no-vec with O2 optimization and see if this works.
Option 2: Try disabling Interprocedural optimization (IPO) and also try -fno-inline -no-ip.

Another option is to narrow down the file which is responsible by building part of the project with O1 but the rest with O2. Narrowing down the file and sharing that with us might help us understand things better. Let me know if you find anything from the above experiments.

Thanks and Regards
Anoop

0 Kudos
John_W_3
Beginner
1,270 Views

Indeed, using -O3 -no-vec works without error. I am going to try putting -O3 back to reproduce and then do ulimit -s unlimited to see if it is stack overflow. Unfortunately each experiment takes a lot of time. I have whittled down the number of files that get recompiled but it's still at 20 minutes per build. I will continue trying to get that down.

Edit: looking at ulimit -a does not give me a sense that unlimiting the stack size will help, but we will see.

-bash-4.1$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 127688
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 16384
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) unlimited
cpu time               (seconds, -t) unlimited
max user processes              (-u) 127688
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

 

0 Kudos
John_W_3
Beginner
1,270 Views

I guess it's not stack overflow if the error persists with ulimit -s unlimited. So -O2 or -O3 fails, -O1 passes. -O2 -no-vec and -O3 -no-vec work. I'm hoping allinea ddt can get me closer to the source of the error, but I'll take suggestions in the meantime.

 

0 Kudos
Reply