Actions

Compiling and testing your software on ALICE

From ALICE Documentation

Compiling and testing your software on ALICE

All nodes in ALICE are running CentOS 7.7 operating system, which is a specific version of Red Hat Enterprise Linux. This means that all the software programs (executable) that the end-user wants to run on ALICE first must be compiled for CentOS 7.7. It also means that you first have to install all the required external software packages on ALICE. Most commonly used compilers are already pre-installed on ALICE and can be used straight away. Also, many popular external software packages, which are regularly used in the scientific community, are also pre-installed.

Check the pre-installed software on ALICE

In order to check all the available modules and their version numbers, which are pre-installed on ALICE enter:

$ module av 2>&1 | more 
--- /cm/shared/easybuild/modules/all --- 
 AMUSE-GPU/12.0.0-foss-2018a-Python-2.7.14
 AMUSE-Miniconda2/4.7.10
 AMUSE-VADER/12.0.0-foss-2018a-Python-2.7.14
 AMUSE/12.0.0-foss-2018a-Python-2.7.14
 AMUSE/13.1.0-foss-2018a-Python-3.6.4                     (D)
 ATK/2.32.0-GCCcore-8.2.0
 Autoconf/2.69-GCCcore-6.3.0
 Autoconf/2.69-GCCcore-6.4.0
 Autoconf/2.69-GCCcore-7.3.0  ......

Or when you want to check whether some specific software, some compiler or some application (e.g., MATLAB) is installed on ALICE.

$ module av 2>&1 | grep -i -e "matlab" 
MATLAB/2019a

As you are not aware of the capitals letters in the module name, we looked for a case-insensitive name with the “-i” option.

When your required application is not available please contact ALICE. Be aware of potential “License Costs”. “Open Source” software is often preferred.

Porting your code

To port a software-program is to translate it from the operating system in which it was developed (e.g., Windows 10) to another operating system (e.g., Red Hat Enterprise Linux on ALICE) so that it can be used there. Porting implies some degree of effort, but not nearly as much as redeveloping the program in the new environment. It all depends on how “portable” you wrote your code. In the simplest case the file or files may simply be copied from one machine to the other. However, in many cases the software is installed on a computer in a way, which depends upon its detailed hardware, software, and setup, with device drivers for particular devices, using installed operating system and supporting software components, and using different directories. In some cases software, usually described as “portable software” is specifically designed to run on different computers with compatible operating systems and processors without any machine-dependent installation; it is sufficient to transfer specified directories and their contents. Hardware and software-specific information are often stored in configuration files in specified locations (e.g., the registry on machines running MS Windows). Software, which is not portable in this sense, will have to be transferred with modifications to support the environment on the destination machine. Whilst programming, it would be wise to stick to certain standards (e.g., ISO/ANSI/POSIX). This will ease the porting of your code to other platforms. Porting your code to the CentOS 7.7 platform is the responsibility of the end-user.

Compiling and building on ALICE

Compiling refers to the process of translating code written in some programming language, e.g., Fortran, C, or C++, to machine code. Building is similar but includes glueing together the machine code resulting from different source files into an executable (or library). The text below guides you through some basic problems typical for small software projects. For larger projects, it is more appropriate to use makefiles or even an advanced build system like CMake. All ALICE nodes run the same version of the Operating System, i.e. CentOS 7.7. So, it is sufficient to compile your program on any compute node. Once you have generated an executable with your compiler, this executable should be able to run on any other compute-node.

  1. A typical process looks like:
  2. Copy your software to the ALICE login-node
  3. Start an interactive session on a compute node;
  4. Compile it;
  5. Test it locally;
  6. Generate your job scripts;
  7. Test it on ALICE
  8. Run it (in parallel);

We assume you’ve copied your software to ALICE

The next step is to request your private compute node.

$ salloc

Compiling a sequential program in C

Go to the examples for chapter 13 and load the foss module:

$ cd ∼/examples/Compiling-and-testing-your-software-on-the-HPC 
$ module load foss 

We now list the directory and explore the contents of the “hello.c” program:

$ ls -l 
total 512 
-rw-r--r-- 1 vsc40000 214 Sep 16 09:42 hello.c 
-rw-r--r-- 1 vsc40000 130 Sep 16 11:39 hello.slurm* 
-rw-r--r-- 1 vsc40000 359 Sep 16 13:55 mpihello.c 
-rw-r--r-- 1 vsc40000 304 Sep 16 13:55 mpihello.slurm 

— hello.c —

6 #include "stdio.h" 
7 int main( int argc, char *argv[] ) 
8 { 
9 int i; 10 for (i=0; i<500; i++) 
11 { 
12 printf("Hello #%d\n", i); 
13 fflush(stdout); 
14 sleep(1); 
15 } 
16 } 

The “hello.c” program is a simple source file, written in C. It’ll print 500 times “Hello #

We first need to compile this C-file into an executable with the gcc-compiler.

First, check the command-line options for “gcc” (GNU C-Compiler), then we compile and list the contents of the directory again:

$ gcc -help 
$ gcc -o hello hello.c 
$ ls -l total 512 -rwxrwxr-x 1 vsc40000 7116 Sep 16 11:43 hello* 
-rw-r--r-- 1 vsc40000 214 Sep 16 09:42 hello.c 
-rwxr-xr-x 1 vsc40000 130 Sep 16 11:39 hello.slurm* 

A new file “hello” has been created. Note that this file has “execute” rights, i.e., it is executable. More often than not, calling gcc – or any other compiler for that matter – will provide you with a list of errors and warnings referring to mistakes the programmer made, such as typos, syntax errors. You will have to correct them first in order to make the code compile. Warnings pinpoint less crucial issues that may relate to performance problems, using unsafe or obsolete language features, etc. It is good practice to remove all warnings from a compilation process, even if they seem unimportant so that a code change that produces a warning does not go unnoticed.

Let’s test this program on the local compute node, which is at your disposal after the “salloc” command:

$ ./hello 
Hello #0 
Hello #1 
Hello #2 
Hello #3 
Hello #4
 ... 

It seems to work, now run it on ALICE

$ sbatch hello.slurm

Compiling a parallel program in C/MPI

$ cd ∼/examples/Compiling-and-testing-your-software-on-the-HPC

List the directory and explore the contents of the “mpihello.c” program:

$ ls -l 
total 512 
total 512 
-rw-r--r-- 1 vsc40000 214 Sep 16 09:42 hello.c 
-rw-r--r-- 1 vsc40000 130 Sep 16 11:39 hello.slurm* 
-rw-r--r-- 1 vsc40000 359 Sep 16 13:55 mpihello.c 
-rw-r--r-- 1 vsc40000 304 Sep 16 13:55 mpihello.slurm

— mpihello.c —

 6 #include <stdio.h> 
 7 #include <mpi.h> 
 8 
 9 main(int argc, char **argv) 
 10 { 
 11 int node, i, j; 
 12 float f; 
 13 
 14 MPI_Init(&argc,&argv); 
 15 MPI_Comm_rank(MPI_COMM_WORLD, &node); 
 16 
 17 printf("Hello World from Node %d.\n", node); 
 18 for (i=0; i<=100000; i++) 
 19 f=i*2.718281828*i+i+i*3.141592654; 
 20 
 21 MPI_Finalize(); 
 22 }

The “mpi_hello.c” program is a simple source file, written in C with MPI library calls. Then, check the command line options for “mpicc” (GNU C-Compiler with MPI extensions), then we compile and list the contents of the directory again:

$ mpicc -help 
$ mpicc -o mpihello mpihello.c 
$ ls -l

A new file “hello” has been created. Note that this program has “execute” rights.

Let’s test this program on the “login” node first:

$ ./mpihello 
Hello World from Node 0.

It seems to work, now run it on ALICE.

$ sbatch mpihello.slurm

Compiling a parallel program in Intel Parallel Studio Cluster Edition

We will now compile the same program, but using the Intel Parallel Studio Cluster Edition compilers. We stay in the examples directory for this chapter:

$ cd ∼/examples/Compiling-and-testing-your-software-on-the-HPC

We will compile this C/MPI -file into an executable with the Intel Parallel Studio Cluster Edition. First, clear the modules (purge) and then load the latest “intel” module:

$ module purge 
$ module load intel

Then, compile and list the contents of the directory again. The Intel equivalent of mpicc is mpiicc.

$ mpiicc -o mpihello mpihello.c 
$ ls -l

Note that the old “mpihello” file has been overwritten. Let’s test this program on the “login” node first:

$ ./mpihello 
Hello World from Node 0.

It seems to work, now run it on ALICE.

$ sbatch mpihello.slurm

Note: We only has a license for the Intel Parallel Studio Cluster Edition for a fixed number of users. As such, it might happen that you have to wait a few minutes before a floating license becomes available for your use.

Note: The Intel Parallel Studio Cluster Edition contains equivalent compilers for all GNU compilers. Hereafter the overview for C, C++ and Fortran compilers.

Sequential Program Parallel Program (with MPI)
GNU Intel GNU Intel
C gcc icc mpicc mpiicc
C++ g++ icpc mpicxx mpiicpc
Fortran gfortran ifort mpif90 mpiifort