<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.snu.edu.in/index.php?action=history&amp;feed=atom&amp;title=Magus02%2FCompiler</id>
	<title>Magus02/Compiler - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.snu.edu.in/index.php?action=history&amp;feed=atom&amp;title=Magus02%2FCompiler"/>
	<link rel="alternate" type="text/html" href="https://wiki.snu.edu.in/index.php?title=Magus02/Compiler&amp;action=history"/>
	<updated>2026-11-04T19:44:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.9</generator>
	<entry>
		<id>https://wiki.snu.edu.in/index.php?title=Magus02/Compiler&amp;diff=1183&amp;oldid=prev</id>
		<title>Deepak: new</title>
		<link rel="alternate" type="text/html" href="https://wiki.snu.edu.in/index.php?title=Magus02/Compiler&amp;diff=1183&amp;oldid=prev"/>
		<updated>2026-04-20T06:40:20Z</updated>

		<summary type="html">&lt;p&gt;new&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{DISPLAYTITLE:Compilers — Magus02 HPC}}&lt;br /&gt;
&amp;lt;div style=&amp;quot;background:#0d1b2a;border:1px solid #1e3a5a;border-radius:8px;padding:12px 18px;margin-bottom:20px;font-size:13px;font-family:monospace;color:#5ba3d9;&amp;quot;&amp;gt;&lt;br /&gt;
📍 [[Magus02/Knowledge_Base|Magus02 Knowledge Base]] → HPC User → Compilers&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A compiler translates human-readable source code (C, C++, Fortran) into executable binary programs. Choosing the right compiler and flags can significantly affect application performance on Magus02.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== General ==&lt;br /&gt;
&lt;br /&gt;
Compilers are loaded via the [[Magus02/Modules|module system]]. Never invoke compilers directly without loading the appropriate module first.&lt;br /&gt;
&lt;br /&gt;
A basic compilation workflow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# 1. Load the compiler module&lt;br /&gt;
$ module load intel/oneapi&lt;br /&gt;
&lt;br /&gt;
# 2. Compile your source code&lt;br /&gt;
$ icc hello_world.c -o hello_world&lt;br /&gt;
&lt;br /&gt;
# 3. Run the resulting binary&lt;br /&gt;
$ ./hello_world&lt;br /&gt;
Hello, World!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Optimization Flags ===&lt;br /&gt;
&lt;br /&gt;
Always compile with optimization enabled for production runs. Common optimization levels:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width:100%;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Flag !! Effect&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;-O0&amp;lt;/code&amp;gt; || No optimization. Fastest compile; use when debugging.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;-O1&amp;lt;/code&amp;gt; || Basic optimizations.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;-O2&amp;lt;/code&amp;gt; || Recommended default for production — good balance of speed and compile time.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;-O3&amp;lt;/code&amp;gt; || Aggressive optimization, including vectorization. May change floating-point behavior.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;-march=native&amp;lt;/code&amp;gt; || Optimize specifically for the current CPU architecture (AMD EPYC / Intel Xeon on Magus02).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Intel Compiler (icc / ifort) ==&lt;br /&gt;
&lt;br /&gt;
The Intel compiler is optimized for Intel and compatible AMD microprocessors and often produces the fastest binaries for numerical codes.&lt;br /&gt;
&lt;br /&gt;
Load the module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ module load intel/oneapi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile C, C++, or Fortran:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ icc   source.c   -O2 -o my_program      # C&lt;br /&gt;
$ icpc  source.cpp -O2 -o my_program      # C++&lt;br /&gt;
$ ifort source.f90 -O2 -o my_program      # Fortran 90&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== GNU Compiler Collection (gcc / gfortran) ==&lt;br /&gt;
&lt;br /&gt;
GCC is a free, open-source compiler available on all platforms. Reliable and widely tested.&lt;br /&gt;
&lt;br /&gt;
Load the module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ module load gcc/11.2.0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compile:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ gcc      source.c   -O2 -o my_program   # C&lt;br /&gt;
$ g++      source.cpp -O2 -o my_program   # C++&lt;br /&gt;
$ gfortran source.f90 -O2 -o my_program   # Fortran&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== LLVM / Clang ==&lt;br /&gt;
&lt;br /&gt;
The LLVM project provides modern, modular compiler infrastructure. Useful for C/C++ and when targeting specific optimization analyses.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ module load llvm&lt;br /&gt;
$ clang   source.c   -O2 -o my_program   # C&lt;br /&gt;
$ clang++ source.cpp -O2 -o my_program   # C++&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PGI / NVIDIA Compilers ==&lt;br /&gt;
&lt;br /&gt;
PGI compilers (now NVIDIA HPC SDK) are particularly useful for GPU programming with OpenACC pragmas.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ module load nvhpc&lt;br /&gt;
$ pgcc   source.c   -O2 -o my_program&lt;br /&gt;
$ pgfort source.f90 -O2 -o my_program&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Compiling Multi-file Projects ==&lt;br /&gt;
&lt;br /&gt;
For programs split across multiple source files, use a linker or a build system:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Compile with multiple source files:&lt;br /&gt;
$ icc file1.c file2.c file3.c -O2 -o my_program&lt;br /&gt;
&lt;br /&gt;
# Or use make (for larger projects with a Makefile):&lt;br /&gt;
$ module load intel/oneapi&lt;br /&gt;
$ make&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* [https://software.intel.com/en-us/intel-compilers Intel Compilers]&lt;br /&gt;
* [https://gcc.gnu.org GNU Compiler Collection]&lt;br /&gt;
* [https://llvm.org LLVM Compiler Infrastructure]&lt;br /&gt;
* [[Magus02/MPI_Usage|MPI Usage — Compiler Wrappers]]&lt;br /&gt;
* [[Magus02/OpenMP_Usage|OpenMP Usage — Compiler Flags]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;div style=&amp;quot;font-family:monospace;font-size:11px;color:#484f58;text-align:right;&amp;quot;&amp;gt;&lt;br /&gt;
[[Magus02/Knowledge_Base|↑ Back to Knowledge Base]] · Maintained by HPC Administration · wiki.snu.edu.in&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Deepak</name></author>
	</entry>
</feed>