Reaching Others University at Buffalo - The State University of New York
Skip to Content

Compiling Code

Basic instructions on compiling codes on the compute cluster.

Compilation of Serial Code

Form for compiling a serial code:  compiler -flags filename

The available compilers are C, C++, Fortran77 and Fortran 90. 

There are several implementations of compilers on the CCR cluster.   These are GNU, INTEL and PGI. 

  • GNU: gcc, g++, gfortran, g77
  • INTEL: icc, icpc, ifort
  • PGI: pgcc, pgCC, pgfortran, pgf77, pgf90

The GNU compilers are in the default path.   A module must be loaded to set the paths for the INTEL and PGI compiler suites.

Basic syntax

Compilation of C code with GNU:

            gcc -o exec filename.c

            where -o specifies the executable file name, which in this case would be exec.  If the -o flag is omitted, then the default executable is a.out.

 

Compilation of C code with INTEL: 

            module load intel

            icc -o exec filename.c

            where -o specifies the executable file name, which in this case would be exec.  If the -o flag is omitted, then the default executable is a.out.

Example of compiling helloworld C program with gcc


[cdc@u2:~]$ cat hello-world.c 
#include <stdio.h>

int main() {
   printf("Hello world!\n");
}

[cdc@u2:~]$ gcc -o hello-gnu hello-world.c 
[cdc@u2:~]$ ./hello-gnu 
Hello world!
[cdc@u2:~]$ 

Example of compiling helloworld C program with icc


[cdc@u2:~]$ cat hello-world.c 
#include <stdio.h>

int main() {
   printf("Hello world!\n");
}

[cdc@u2:~]$ module list
Currently Loaded Modulefiles:
  1) null      2) modules
[cdc@u2:~]$ module avail intel

-------------------------- /util/Modules/modulefiles ---------------------------
intel/10.0          intel/9.0           intel-mpi/4.0
intel/10.1          intel/9.1           intel-mpi/4.0.1
intel/11.0          intel/9.1.040       intel-mpi/4.0.3
intel/11.1(default) intel-ipp/7.0.1     intel-tbb/3.0.3
intel/12.0          intel-mpi/3.1
intel/12.1          intel-mpi/3.2
[cdc@u2:~]$ module load intel/12.1 
[cdc@u2:~]$ icc -o hello-intel hello-world.c 
[cdc@u2:~]$ ./hello-intel 
Hello world!
[cdc@u2:~]$