Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
habrok:additional_information:course_material:advanced_exercises_solutions [2023/09/19 11:30] – peregrine -> habrok pedro | habrok:additional_information:course_material:advanced_exercises_solutions [2024/10/28 14:40] (current) – [Exercise 0] Changed to GitLab link aurel | ||
---|---|---|---|
Line 20: | Line 20: | ||
===== Exercise 0 ===== | ===== Exercise 0 ===== | ||
- | The files needed to complete these exercises are on [[https://github.com/rug-cit-hpc/ | + | The files needed to complete these exercises are on [[https://gitrepo.service.rug.nl/cit-hpc/habrok/ |
< | < | ||
- | git clone https://github.com/rug-cit-hpc/ | + | git clone https://gitrepo.service.rug.nl/cit-hpc/habrok/ |
</ | </ | ||
Line 62: | Line 62: | ||
< | < | ||
- | module load foss/2020a | + | module load foss/2022b |
</ | </ | ||
Line 96: | Line 96: | ||
* '' | * '' | ||
- | Most of the images on the Web are in formats other than '' | + | Most of the images on the Web are in formats other than '' |
< | < | ||
+ | module load ImageMagick/ | ||
convert source_image.jpg source_image.rgb | convert source_image.jpg source_image.rgb | ||
</ | </ | ||
Line 116: | Line 117: | ||
module purge | module purge | ||
# Load the compilers | # Load the compilers | ||
- | module load foss/2020a | + | module load foss/2022a |
+ | # Load the conversion tool | ||
+ | module load ImageMagick/ | ||
# Compile the program | # Compile the program | ||
make | make | ||
Line 141: | Line 144: | ||
#SBATCH --mem=4GB | #SBATCH --mem=4GB | ||
#SBATCH --time=00: | #SBATCH --time=00: | ||
- | #SBATCH --partition=short | + | #SBATCH --partition=regular |
#SBATCH --job-name=Edge_detection | #SBATCH --job-name=Edge_detection | ||
Line 147: | Line 150: | ||
module purge | module purge | ||
# Load the compilers | # Load the compilers | ||
- | module load foss/2020a | + | module load foss/2022b |
+ | # Load the conversion tool | ||
+ | module load ImageMagick/ | ||
# Compile the program | # Compile the program | ||
make | make | ||
Line 195: | Line 200: | ||
#SBATCH --mem=4GB | #SBATCH --mem=4GB | ||
#SBATCH --time=00: | #SBATCH --time=00: | ||
- | #SBATCH --partition=short | + | #SBATCH --partition=regular |
#SBATCH --job-name=Edge_detection | #SBATCH --job-name=Edge_detection | ||
Line 201: | Line 206: | ||
module purge | module purge | ||
# Load the compilers | # Load the compilers | ||
- | module load foss/2020a | + | module load foss/2022b |
+ | # Load the conversion tool | ||
+ | module load ImageMagick/ | ||
# Compile the program | # Compile the program | ||
make | make | ||
Line 216: | Line 223: | ||
# Remove the intermediate files | # Remove the intermediate files | ||
rm $1.rgb conv_$1.rgb | rm $1.rgb conv_$1.rgb | ||
+ | |||
</ | </ | ||
- | You can submit the job using: | ||
- | < | ||
- | sbatch jobscript.sh Microcrystals.jpg | ||
- | </ | ||
</ | </ | ||
+ | |||
==== Exercise 1.2: Validate input ==== | ==== Exercise 1.2: Validate input ==== | ||
Line 268: | Line 273: | ||
#SBATCH --mem=4GB | #SBATCH --mem=4GB | ||
#SBATCH --time=00: | #SBATCH --time=00: | ||
- | #SBATCH --partition=short | + | #SBATCH --partition=regular |
#SBATCH --job-name=Edge_detection | #SBATCH --job-name=Edge_detection | ||
Line 284: | Line 289: | ||
module purge | module purge | ||
# Load the compilers | # Load the compilers | ||
- | module load foss/2020a | + | module load foss/2022b |
+ | # Load the conversion tool | ||
+ | module load ImageMagick/ | ||
# Compile the program | # Compile the program | ||
make | make | ||
Line 311: | Line 318: | ||
As you probably have seen, when studying the jobscript, the image size needs to be specified to the convolution program and the convert program. So for now our script only works for images with a predefined size. | As you probably have seen, when studying the jobscript, the image size needs to be specified to the convolution program and the convert program. So for now our script only works for images with a predefined size. | ||
- | In order to fix this we need to be able to extract the image size from an image file. The program '' | + | In order to fix this we need to be able to extract the image size from an image file. The program '' |
**Run the program identify on the image file.** As you can see from the result the size of the image is returned by '' | **Run the program identify on the image file.** As you can see from the result the size of the image is returned by '' | ||
Line 324: | Line 331: | ||
**Run these commands on the imagefile to see what they do.** | **Run these commands on the imagefile to see what they do.** | ||
- | As you have seen these commands result in numbers that we could use in our script. In order to store a number | + | As you have seen these commands result in numbers that we could use in our script. In order to store the output |
< | < | ||
myvar=$( command ) | myvar=$( command ) | ||
Line 343: | Line 350: | ||
#SBATCH --mem=4GB | #SBATCH --mem=4GB | ||
#SBATCH --time=00: | #SBATCH --time=00: | ||
- | #SBATCH --partition=short | + | #SBATCH --partition=regular |
#SBATCH --job-name=Edge_detection | #SBATCH --job-name=Edge_detection | ||
Line 356: | Line 363: | ||
if [ -e $1 ] | if [ -e $1 ] | ||
then | then | ||
+ | # Clean up the module environment | ||
+ | module purge | ||
+ | # Load the conversion and identification tool | ||
+ | module load ImageMagick/ | ||
# Determine width and height of the image | # Determine width and height of the image | ||
width=$(identify -format " | width=$(identify -format " | ||
Line 362: | Line 373: | ||
echo " | echo " | ||
| | ||
- | # Clean up the module environment | ||
- | module purge | ||
# Load the compilers | # Load the compilers | ||
- | module load foss/2020a | + | module load foss/2022b |
# Compile the program | # Compile the program | ||
make | make | ||
Line 411: | Line 420: | ||
#SBATCH --mem=4GB | #SBATCH --mem=4GB | ||
#SBATCH --time=00: | #SBATCH --time=00: | ||
- | #SBATCH --partition=short | + | #SBATCH --partition=regular |
#SBATCH --job-name=Sharpening | #SBATCH --job-name=Sharpening | ||
Line 429: | Line 438: | ||
dirname=$(dirname $1) | dirname=$(dirname $1) | ||
filename=$(basename $1) | filename=$(basename $1) | ||
+ | | ||
+ | # Clean up the module environment | ||
+ | module purge | ||
+ | # Load the conversion and identification tools | ||
+ | module load ImageMagick/ | ||
+ | # Load the compilers | ||
+ | module load foss/2022b | ||
| | ||
# Determine width and height of the image | # Determine width and height of the image | ||
Line 436: | Line 452: | ||
echo " | echo " | ||
| | ||
- | # Clean up the module environment | ||
- | module purge | ||
- | # Load the compilers | ||
- | module load foss/2020a | ||
# Compile the program | # Compile the program | ||
make | make | ||
Line 508: | Line 520: | ||
#SBATCH --mem=4GB | #SBATCH --mem=4GB | ||
#SBATCH --time=00: | #SBATCH --time=00: | ||
- | #SBATCH --partition=short | + | #SBATCH --partition=regular |
#SBATCH --job-name=Sharpening | #SBATCH --job-name=Sharpening | ||
Line 522: | Line 534: | ||
then | then | ||
echo " | echo " | ||
+ | |||
+ | # Clean up the module environment | ||
+ | module purge | ||
+ | # Load the conversion and identification tools | ||
+ | module load ImageMagick/ | ||
+ | # Load the compilers | ||
+ | module load foss/2022b | ||
# Get the directory in which the file is stored | # Get the directory in which the file is stored | ||
dirname=$(dirname " | dirname=$(dirname " | ||
filename=$(basename " | filename=$(basename " | ||
+ | | ||
# Determine width and height of the image | # Determine width and height of the image | ||
width=$(identify -format " | width=$(identify -format " | ||
Line 532: | Line 551: | ||
echo " | echo " | ||
echo " | echo " | ||
- | + | | |
- | # Clean up the module environment | + | |
- | module purge | + | |
- | # Load the compilers | + | |
- | module load foss/2020a | + | |
# Compile the program | # Compile the program | ||
make | make | ||
Line 546: | Line 561: | ||
# Convert the resulting file back to jpg format | # Convert the resulting file back to jpg format | ||
convert -size ${width}x${height} | convert -size ${width}x${height} | ||
+ | | ||
# Remove the intermediate files | # Remove the intermediate files | ||
rm " | rm " | ||
Line 571: | Line 586: | ||
module purge | module purge | ||
# Load the compilers | # Load the compilers | ||
- | module load foss/2020a | + | module load foss/2022b |
# Compile the program | # Compile the program | ||
make | make | ||
Line 610: | Line 625: | ||
module purge | module purge | ||
# Load the compilers | # Load the compilers | ||
- | module load foss/2020a | + | module load foss/2022b |
# Compile the program | # Compile the program | ||
make | make | ||
Line 634: | Line 649: | ||
** Since we are going to submit all work from a single job script, we need to make sure that the executable is in place, before we can run the script. ** This can be achieved by running the following commands: | ** Since we are going to submit all work from a single job script, we need to make sure that the executable is in place, before we can run the script. ** This can be achieved by running the following commands: | ||
< | < | ||
- | module load foss/2020a | + | module load foss/2022b |
make | make | ||
</ | </ | ||
Line 640: | Line 655: | ||
First we need a list of all images to be processed, and this time we are going to store this list in a text file instead of in a variable. | First we need a list of all images to be processed, and this time we are going to store this list in a text file instead of in a variable. | ||
- | **Run a command (you can use '' | + | **Run a command (you can use '' |
Now open the script '' | Now open the script '' | ||
Line 653: | Line 668: | ||
echo " | echo " | ||
</ | </ | ||
- | **Insert the right command between the parentheses: | + | **Insert the right command between the parentheses: |
Finally, to make this a job array, we have to set a range that defines how many times this job is going to be run. Since we use '' | Finally, to make this a job array, we have to set a range that defines how many times this job is going to be run. Since we use '' | ||
Line 677: | Line 692: | ||
#SBATCH --mem=4GB | #SBATCH --mem=4GB | ||
#SBATCH --time=00: | #SBATCH --time=00: | ||
- | #SBATCH --partition=short | + | #SBATCH --partition=regular |
#SBATCH --job-name=Edge_Detection | #SBATCH --job-name=Edge_Detection | ||
#SBATCH --array=1-31 | #SBATCH --array=1-31 | ||
Line 694: | Line 709: | ||
image=$(cat " | image=$(cat " | ||
echo " | echo " | ||
+ | |||
+ | # Clean up the module environment | ||
+ | module purge | ||
+ | # Load the conversion and identification tools | ||
+ | module load ImageMagick/ | ||
# Get the directory in which the file is stored | # Get the directory in which the file is stored | ||
Line 705: | Line 725: | ||
echo " | echo " | ||
| | ||
- | # Clean up the module environment | ||
- | module purge | ||
- | # Load the compilers | ||
- | module load foss/2020a | ||
- | |||
# Convert the jpg file to the rgb format for easy processing | # Convert the jpg file to the rgb format for easy processing | ||
convert " | convert " | ||
Line 743: | Line 758: | ||
You can study the resulting image using the command: | You can study the resulting image using the command: | ||
< | < | ||
+ | module load ImageMagick/ | ||
display -resize 30% conv_Microcrystals.jpg | display -resize 30% conv_Microcrystals.jpg | ||
</ | </ | ||
Line 755: | Line 771: | ||
#SBATCH --mem=4GB | #SBATCH --mem=4GB | ||
#SBATCH --time=00: | #SBATCH --time=00: | ||
- | #SBATCH --partition=short | + | #SBATCH --partition=regular |
#SBATCH --job-name=Blurring | #SBATCH --job-name=Blurring | ||
#SBATCH --output=singlecpu.out | #SBATCH --output=singlecpu.out | ||
Line 762: | Line 778: | ||
module purge | module purge | ||
# Load the compilers | # Load the compilers | ||
- | module load foss/2020a | + | module load foss/2022b |
+ | # Load the conversion tool | ||
+ | module load ImageMagick/ | ||
# Compile the program | # Compile the program | ||
make | make | ||
Line 789: | Line 807: | ||
After performing this exercise, you should obtain something like the following: | After performing this exercise, you should obtain something like the following: | ||
- | {{:peregrine: | + | {{:habrok: |
The '' | The '' | ||
Line 824: | Line 842: | ||
**Run the blurring app with 2, 4, 8, and 16 MPI tasks, each using one core and running on a separate node.** Make note of the runtimes, as well as the overall wallclock time. How does this differ from the previous exercise? | **Run the blurring app with 2, 4, 8, and 16 MPI tasks, each using one core and running on a separate node.** Make note of the runtimes, as well as the overall wallclock time. How does this differ from the previous exercise? | ||
+ | |||
+ | You can try to resubmit the job with 4 nodes to a '' | ||
+ | |||
+ | The " | ||
+ | |||
<hidden Solution> | <hidden Solution> | ||
Line 832: | Line 855: | ||
After performing this exercise, you should get something like this: | After performing this exercise, you should get something like this: | ||
- | {{:peregrine: | + | {{:habrok: |
It is interesting to compare this graph with the one from exercise 2.2. The main difference is in '' | It is interesting to compare this graph with the one from exercise 2.2. The main difference is in '' | ||
Line 854: | Line 877: | ||
So far, you've been using either multiple CPUs on a single machine (OpenMP), or on multiple machines (MPI), to parallelize and speed up the image processing. In this exercise, you will have a look at how to use GPUs to achieve parallelization. In the folder named '' | So far, you've been using either multiple CPUs on a single machine (OpenMP), or on multiple machines (MPI), to parallelize and speed up the image processing. In this exercise, you will have a look at how to use GPUs to achieve parallelization. In the folder named '' | ||
- | We've reserved one GPU node with 2 k40 GPUs for this course. The reservation is called '' | + | We've reserved one GPU node with 2 V100 GPUs for this course. The reservation is called '' |
< | < | ||
#SBATCH --reservation=advanced_course | #SBATCH --reservation=advanced_course | ||
</ | </ | ||
- | **Request 1 (one) GPU of type k40 on the '' | + | **Request 1 (one) GPU of type V100 on the '' |
**Compare the times from exercise 2.2 with what you obtain now**. You might want to make the problem a bit harder by processing all the files from the '' | **Compare the times from exercise 2.2 with what you obtain now**. You might want to make the problem a bit harder by processing all the files from the '' | ||
Line 864: | Line 887: | ||
Programming the GPU is not for the faint of heart, though OpenACC makes it relatively easy. If you read C code, **study the code and try to figure out where is the GPU used**. If you plan to use an existing application with the GPU, you needn' | Programming the GPU is not for the faint of heart, though OpenACC makes it relatively easy. If you read C code, **study the code and try to figure out where is the GPU used**. If you plan to use an existing application with the GPU, you needn' | ||
- | <hidden Solution> | + | <hidden Solution> |
- | + | < | |
- | ''# | + | #SBATCH --gpus-per-node=v100:1 |
- | + | #SBATCH --reservation=advanced_course | |
- | '' | + | </ |
</ | </ | ||