Installing and developing your own C, C++, or Fortran program in the CSC computing environment

Case A: you have the source code, you want to install and run it

  1. Create a directory for your code. The recommended location is under the /projappl directory of your project:
mkdir -p /projappl/<project>/myprog    # replace <project> with your CSC project, e.g. project_2001234
  1. You need the source files of the code. Depending on the software, you can typically download them from e.g. GitHub. If you have the source code on your own computer, use e.g. scp to upload the data to the supercomputer.
  2. If the source files are distributed as a zip file, use unzip to decompress:
unzip filename.zip    # modify the filename accordingly
  1. Read and follow any instructions on how to install. Usually, the code comes with a README or INSTALL file outlining the installation procedure.
  2. When compiling, consider using the fast local disk on the login nodes ($TMPDIR) to move I/O load away from the parallel file system.

Scenario A1: The code uses cmake

  1. Load the cmake module:
module load cmake
  1. Download and install external libraries that the code might need. Always check first if these can be found as pre-installed modules (the most common ones are available):
module spider <modulename>   # replace <modulename>, e.g. fftw
  1. Create and move to a build directory in the root of the source code:
mkdir build
cd build
  1. Run cmake with cmake /path/to/source/code:
cmake ..
  1. If you get errors, try to fix the problems. Sometimes it might be easiest to remove everything and start from the beginning, i.e. by unzipping the .zip file.
  2. After cmake, run make to compile the specific applications you want to use:
make
  1. Ask help from CSC Service Desk if you get stuck.

Scenario A2: The code comes with a Makefile

  1. module load or install separately all required libraries. Check for availability of modules with:
module spider <modulename>    # replace <modulename>, e.g. fftw
  1. Load the library modules with:
module load <modulename>/<version>   # replace <modulename>/<version>, e.g. fftw/3.3.10-mpi
  1. Edit the Makefile manually or by running ./configure to replace compile and link commands with proper ones for Mahti or Puhti.
  2. Run the command make to compile and make install to install. Custom installation location is typically specified with the --prefix option of the configure script.
./configure --prefix=/projappl/<project>/myprog    # replace <project> with your CSC project, e.g. project_2001234 
make
make install
  1. Read any error messages and try to fix the possible issues.
  2. Ask help from CSC Service Desk if you get stuck.

Case B: You want to write your own code

  1. You need an editor.
  2. Launch an editor and write the code. If not developing locally, consider using the Puhti web interface and e.g. VSCode.
  3. Compile your code on Puhti or on Mahti.
  4. Fix bugs until compiler accepts code.

Exercise

  • Write your own simple C/C++/Fortran code, compile it and run it.