IMSL Numerical Libraries

From TAMUQ Research Computing User Documentation Wiki
Jump to navigation Jump to search

Introduction

IMSL is a suite of cross platform numerical libraries available in Fortran, C, Java, and Python. IMSL Libraries are a comprehensive collection of mathematical, statistical, financial, data mining and machine learning functions developers can embed into their sophisticated numerical analysis applications [1].

Raad2 supports C, Fortran and Java libraries of IMSL version 2021.0.0. Please see respective sections below for details.

Running C code with ISML on raad2

This section demonstrates compiling a sample C program with the IMSL C library using the GCC 7.5.0 compiler (which is the default gcc compiler you find upon login). The sample code is taken from the IMSL's examples folder. Refer to IMSL C Numerical Libraries for detailed documentation.

Step 1: Load the IMSL C Library module

module load imsl/cnl/gcc750

This modulefile currently does not make any changes to the environment, but simply prints out the command the user needs to run in order to setup the environment for IMSL. Step 2 shows that command.

Step 2: Source the configuration script

source /lustre/sw/xc40/cle7/imsl/imsl/cnl-2021.0.0/lnxgc750x64/bin/cnlsetup.sh

Simply copy and paste the command displayed by the previous module command to your command prompt and hit enter to set up your environment.

Step 3: Compile the source code

The sample code below (cmath.c) is copied from the IMSL examples folder. If you like, you may do a cd $CNL_EXAMPLES to explore the contents of that folder.

$CC $CFLAGS -o cmath cmath.c $LINK_CNL

The contents of the cmath.c file can be seen below. A successful compilation will produce an executable named "cmath" in the current directory.

/* $CNL_EXAMPLES/validate/cmath.c */
int main(void)
{
    int		n = 3;
    float	*x;
    static float	a[] = { 1.0, 3.0, 3.0, 1.0, 3.0, 4.0, 1.0, 4.0, 3.0 };
    static float	b[] = { 1.0, 4.0, -1.0 };

    /*
     * Verify the version of the library we are running by 
     * retrieving the version number via imsl_version(). 
     * Verify correct installation of the error message file 
     * by retrieving the customer number via imsl_version().
     */
    char	*library_version = imsl_version(IMSL_LIBRARY_VERSION);
    char	*customer_number = imsl_version(IMSL_LICENSE_NUMBER);

    printf("Library version:  %s\n", library_version);
    printf("Customer number:  %s\n", customer_number);

	/* Solve Ax = b for x */
    x = imsl_f_lin_sol_gen(n, a, b, 0);
	/* Print x */
    imsl_f_write_matrix("Solution, x of Ax = b", 1, n, x, 0);
    
    /* Generate Error to access error message file */
    n =-10;

    printf ("\nThe next call will generate an error \n");
    x = imsl_f_lin_sol_gen(n, a, b, 0);
}

Step 4: Create a Slurm Job File (imslDemo.job)

Please adjust the parameters according to your simulation's requirements.

#!/bin/bash
#SBATCH -J imslDemo
#SBATCH -p express
#SBATCH --qos=ex
#SBATCH --time=00:05:00
#SBATCH --hint=nomultithread
#SBATCH --ntasks=1
#SBATCH --output=imslDemo.o%j
#SBATCH --error=imslDemo.e%j
#SBATCH --gres=craynetwork:0

echo "Starting at $(date)"
echo "SLURM_JOBID         = $SLURM_JOBID"
echo "SLURM_JOB_NODELIST  = $SLURM_JOB_NODELIST"
echo "SLURM_CPUS_PER_TASK = $SLURM_CPUS_PER_TASK"
echo "Working directory   = $SLURM_SUBMIT_DIR"


module load imsl/cnl/gcc750
source /lustre/sw/xc40/cle7/imsl/imsl/cnl-2021.0.0/lnxgc750x64/bin/cnlsetup.sh

srun ./cmath

Step 5: Submit the Job

sbatch imslDeml.job

Step 6: Analyze the output

After the job finishes, it will create two files (output and error files) in the working directory. The file imslDemo.o<job_id> will contain the program output and imslDemo.e<job_id> the error (if any).

Running Fortran code with ISML on raad2

This section demonstrates compiling a sample Fortran program with the IMSL Fortran library using the Intel Fortran compiler. The IMSL Fortran library has been tested successfully with the Intel Fortran version 19.1.3.304 (which is available on raad2). Refer to IMSL Fortran Numerical Libraries for detailed documentation.

Step 1: Load the Intel Fortran Compiler module

module load intel/19.1.3.304

Step 2: Load the IMSL Fortran Library module

module load imsl/fnl/intelps2020

This modulefile currently does not make any changes to the environment, but simply prints out the command the user needs to run in order to setup the environment for IMSL. Step 3 shows that command.

Step 3: Source the configuration script

source /lustre/sw/xc40/cle7/imsl/imsl/fnl-2021.0.0/sus150in201x64/bin/fnlsetup.sh

Simply copy and paste the command displayed by the previous module command to your command prompt and hit enter to set up your environment.

Step 4: Compile the source code

The sample code below (imslmp.f90) is copied from the IMSL examples folder. If you like, you may do a cd $FNL_EXAMPLES to explore the contents of that folder.

$FC $F90FLAGS -o imslmp imslmp.f90 $LINK_FNL

The contents of the imslmp.f90 file can be seen below. A successful compilation will produce an executable named "imslmp" in the current directory.

/* $FNL_EXAMPLES/validate/imslmp.f90 */
! Use files
 
       use rand_gen_int
       use show_int
 
!  Declarations
 
       real (kind(1.e0)), parameter:: zero=0.e0
       real (kind(1.e0)) x(5)
       type (s_options) :: iopti(2)=s_options(0,zero)
       character VERSION*48, VERML*48
       external VERML
 
!  Start the random number generator with a known seed.
       iopti(1) = s_options(s_rand_gen_generator_seed,zero)
       iopti(2) = s_options(123,zero)
       call rand_gen(x, iopt=iopti)
 
!     Verify the version of the library we are running
!     by retrieving the version number via verml().
!
      VERSION = VERML(1)
      WRITE(*,*) 'Library version:  ', VERSION

!  Get the random numbers
       call rand_gen(x)
 
!  Output the random numbers
       call show(x,text='                              X')

! Generate error
       iopti(1) = s_options(15,zero)
       call rand_gen(x, iopt=iopti)
 
       end

Step 5: Create a Slurm Job File (imslDemo.job)

Please adjust the parameters according to your simulation's requirements.

#!/bin/bash
#SBATCH -J imslDemo
#SBATCH -p express
#SBATCH --qos=ex
#SBATCH --time=00:05:00
#SBATCH --hint=nomultithread
#SBATCH --ntasks=1
#SBATCH --output=imslDemo.o%j
#SBATCH --error=imslDemo.e%j
#SBATCH --gres=craynetwork:0

echo "Starting at $(date)"
echo "SLURM_JOBID         = $SLURM_JOBID"
echo "SLURM_JOB_NODELIST  = $SLURM_JOB_NODELIST"
echo "SLURM_CPUS_PER_TASK = $SLURM_CPUS_PER_TASK"
echo "Working directory   = $SLURM_SUBMIT_DIR"

module load intel/19.1.3.304
module load imsl/fnl/intelps2020
source /lustre/sw/xc40/cle7/imsl/imsl/fnl-2021.0.0/sus150in201x64/bin/fnlsetup.sh

srun ./imslmp

Step 6: Submit the Job

sbatch imslDeml.job

Step 7: Analyze the output

After the job finishes, it will create two files (output and error files) in the working directory. The file imslDemo.o<job_id> will contain the program output and imslDemo.e<job_id> the error (if any).

References