In the provided Makefile, the C++ compiler uses this command to build genScan:
g++ genScan.cpp -Wall -ansi -pedantic -std=c++11 -o genScan -fopenmpIn this command:
We can change that by tweaking the Makefile. Using your text editor, open Makefile, find the line that looks like this:
CFLAGS = -Wall -ansi -std=c++11and change it to read:
CFLAGS = -O2 -Wall -ansi -std=c++11
Compiler optimization is having the compiler spend extra time translating our program into the native binary code, looking for ways to make the binary program faster, smaller, or both.
The GNU compilers support four optimization levels:
-O0 (level zero) performs no optimizations;
the compiler just builds the program as fast as possible.
This is g++'s default setting if the user
doesn't specify a level.
-O1 (level one) performs simple optimizations--improvements
that won't slow down the build very much.
-O2 (level two) performs all optimizations that
will not increase the size of the binary program.
-O3 (level three) performs all available optimizations.
The change we just made to the Makefile will cause g++ to perform level two optimization instead of level zero, which nearly always speeds up the resulting program.