Exercises

Introduction

Getting familiar with Julia REPL

Is is important in this course that you know how to navigate on the Julia command line. This exercise will help you to become more familiar with the REPL. Do the following steps:

  • Start a Julia session. In the Julian mode, compute the sum the numbers 5 and 6

  • Change to the shell mode and display the current directory

  • Now, go to the package mode and list the currently installed packages

  • Finally, display help information of the function println in help mode.

Load and run

Loading modules and running scripts

Load the Julia version 1.8.5 and run the following serial script (serial-sum.jl) which accepts two integer arguments as input:

x = parse( Int32, ARGS[1] )
y = parse( Int32, ARGS[2] )
summ = x + y
println("The sum of the two numbers is ", summ)

Packages and isolated environments

Project environment

Create a project environment called new-env and activate it. Then, install the package CSV in this environment. For your knowledge, CSV is a package that offers tools for dealing with .csv files. After this, check that this package was installed. Finally, deactivate the environment.

Package environment

Create a package environment called new_pack and activate it. Then, install the package CSV in this environment. For your knowledge, CSV is a package that offers tools for dealing with .csv files. After this, check that this package was installed. Finally, deactivate the environment.

Batch mode

Serial code

Run a serial script

Run the serial script serial-sum.jl:

x = parse( Int32, ARGS[1] )
y = parse( Int32, ARGS[2] )
summ = x + y
println("The sum of the two numbers is ", summ)

This scripts accepts two integers as command line arguments.

GPU code

Run the GPU script

Run the following script script-gpu.jl. Why are we running the simulations twice? Note that at UPPMAX you will need a project will access to Snowy (or Bianca)

using CUDA

CUDA.versioninfo()

N = 2^8
x = rand(N, N)
y = rand(N, N)

A = CuArray(x)
B = CuArray(y)

# Calculation on CPU
@time x*y
# Calculation on GPU
@time A*B

# Calculation on CPU
@time x*y
# Calculation on GPU
@time A*B

Machine Learning job on GPUs (HPC2N)

Julia has already several packages for ML, one of them is Flux (https://fluxml.ai/). We will work with one of the test cases provided by Flux which deals with a data set of tiny images (CIFAR10). Follow this steps:

julia> using MLDatasets: CIFAR10
julia> x, y = CIFAR10(:train)[:]
  • Change the number of epochs in the vgg_cifar10.jl script from 50 to something shorter like 5.

  • Submit the job with the script:

#!/bin/bash
#SBATCH -A Project-ID        # your project_ID
#SBATCH -J job-serial        # name of the job
#SBATCH -n 1                 # nr. tasks
#SBATCH --time=00:20:00      # requested time
#SBATCH --error=job.%J.err   # error file
#SBATCH --output=job.%J.out  # output file
#SBATCH --gres=gpu:v100:1     # 1 GPU v100 card

ml purge  > /dev/null 2>&1
ml Julia/1.8.5-linux-x86_64
ml CUDA/11.4.1

julia <fix-activate-environment> <fix-name-script>.jl