gfortran中-native编译选项的等效替代方案咨询
Let's break down what's happening here and how to fix it quickly:
The -native flag you're using was an older option for legacy Fortran compilers (like the original f77) that told the compiler to optimize code specifically for the CPU architecture of the machine you're compiling on. Modern versions of gfortran have replaced this with a more flexible, standardized set of flags.
The Direct Replacement for -native
The exact equivalent in gfortran is the -march=native flag. This does exactly what -native used to do: it auto-detects your host CPU's architecture, enables all compatible instruction sets, and tunes the generated code for optimal performance on that specific hardware.
Updating Your Makefile
Modify your FLT_FLAGS line to replace -native with -march=native:
FLT_FLAGS = -march=native -libmil
Your compile command will then become:
gfortran -O -march=native -libmil -c a2.f
(Note: If your f77 command is just an alias for gfortran, this will work as-is. If not, you might need to replace f77 with gfortran in your Makefile to ensure you're using the modern compiler.)
Optional: Fine-Grained Control
If you need to target a specific CPU architecture (instead of relying on the current machine), you can specify it explicitly with -march=<cpu-type>. For example:
-march=haswellfor Intel Haswell CPUs-march=zen3for AMD Zen 3 CPUs-mtune=nativeif you only want to tune performance for the host CPU without enabling new instruction sets (useful for broader compatibility)
Just make sure to pick an architecture that matches your target hardware to get the best results.
内容的提问来源于stack exchange,提问作者Vladimir Vargas

