Tutorial: Compiling, Makefile, Parallel jobs

Similar documents
Workshop Agenda Feb 25 th 2015

GNU make... Martin Ohlerich, Parallel Programming of High Performance Systems

CS Basics 15) Compiling a C prog.

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

Our new HPC-Cluster An overview

bwunicluster Tutorial Access, Data Transfer, Compiling, Modulefiles, Batch Jobs

Practical Introduction to Message-Passing Interface (MPI)

bwunicluster Tutorial Access, Data Transfer, Compiling, Modulefiles, Batch Jobs

Makefile Tutorial. Eric S. Missimer. December 6, 2013

JURECA Tuning for the platform

2 Compiling a C program

HPC User Environment

Introduction to OpenMP. Lecture 2: OpenMP fundamentals

Cluster Clonetroop: HowTo 2014

Make was originally a Unix tool from 1976, but it has been re-implemented several times, notably as GNU Make.

EE/CSCI 451 Introduction to Parallel and Distributed Computation. Discussion #4 2/3/2017 University of Southern California

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

Introduction to OpenMP

Parallel Programming Languages 1 - OpenMP

Hybrid MPI/OpenMP parallelization. Recall: MPI uses processes for parallelism. Each process has its own, separate address space.

Intermediate Programming, Spring 2017*

CS240: Programming in C

CS691/SC791: Parallel & Distributed Computing

Part One: The Files. C MPI Slurm Tutorial - Hello World. Introduction. Hello World! hello.tar. The files, summary. Output Files, summary

Lab MIC Offload Experiments 7/22/13 MIC Advanced Experiments TACC

30 Nov Dec Advanced School in High Performance and GRID Computing Concepts and Applications, ICTP, Trieste, Italy

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Shared Memory Programming With OpenMP Computer Lab Exercises

Shared Memory Programming With OpenMP Exercise Instructions

27-Sep CSCI 2132 Software Development Lecture 10: Formatted Input and Output. Faculty of Computer Science, Dalhousie University. Lecture 10 p.

[Software Development] Makefiles. Davide Balzarotti. Eurecom Sophia Antipolis, France

Implementation of Parallelization

Lecture 4: OpenMP Open Multi-Processing

Kurt Schmidt. May 23, 2018

Shared memory programming model OpenMP TMA4280 Introduction to Supercomputing

Supercomputing environment TMA4280 Introduction to Supercomputing

Practical Introduction to

Maemo Diablo GNU Make and makefiles Training Material

Advanced Message-Passing Interface (MPI)

OpenMP Exercises. These exercises will introduce you to using OpenMP for parallel programming. There are four exercises:

Overview: The OpenMP Programming Model

OpenMP Programming. Aiichiro Nakano

CS240: Programming in C. Lecture 2: Overview

Shared Memory programming paradigm: openmp

OPEN MP and MPI on Kingspeak chpc cluster

Linux Systems Administration Shell Scripting Basics. Mike Jager Network Startup Resource Center

Working on the NewRiver Cluster

Compiling applications for the Cray XC

Compilation & linkage. Compilation & linkage. Make. Compilation & linkage. Explicit rules. What makefile contains

bwfortreff bwhpc user meeting

CAAM 420 Fall 2012 Lecture 15. Roman Schutski

CS2141 Software Development using C/C++ Compiling a C++ Program

Practical Introduction to

Outline. COMP 2718: Software Development Tools: gcc and make. C and Java 3/28/16

Errors During Compilation and Execution Background Information

CS 470 Spring Mike Lam, Professor. OpenMP

Introduction to OpenMP. OpenMP basics OpenMP directives, clauses, and library routines

Distributed Memory Programming With MPI Computer Lab Exercises

Compilation and Parallel Start

The C Preprocessor Compiling and Linking Using MAKE

We d like to hear your suggestions for improving our indexes. Send to

CMPT 300. Operating Systems. Brief Intro to UNIX and C

Makefile Brief Reference

SCALABLE HYBRID PROTOTYPE

Shared Memory Programming with OpenMP

Session 4: Parallel Programming with OpenMP

DDT: A visual, parallel debugger on Ra

Introduction to GALILEO

CMPSC 311- Introduction to Systems Programming Module: Build Processing

UBDA Platform User Gudie. 16 July P a g e 1

CS 470 Spring Mike Lam, Professor. OpenMP

Reliable C++ development - session 1: From C to C++ (and some C++ features)

Lab: Scientific Computing Tsunami-Simulation

Effective Use of CCV Resources

Parallel Programming: OpenMP

Follow us on Twitter for important news and Compiling Programs

Introduction to Supercomputing

OpenMP Fundamentals Fork-join model and data environment

Open Multi-Processing: Basic Course

High Performance Computing: Tools and Applications

Parallel Tools Platform for Judge

COMP4510 Introduction to Parallel Computation. Shared Memory and OpenMP. Outline (cont d) Shared Memory and OpenMP

CSC 2500: Unix Lab Fall 2016

Working with Shell Scripting. Daniel Balagué

Hybrid Programming with MPI and OpenMP. B. Estrade

Parallele Numerik. Blatt 1

UvA-SARA High Performance Computing Course June Clemens Grelck, University of Amsterdam. Parallel Programming with Compiler Directives: OpenMP

Hybrid MPI+OpenMP Parallel MD

OpenMP Introduction. CS 590: High Performance Computing. OpenMP. A standard for shared-memory parallel programming. MP = multiprocessing

P a g e 1. HPC Example for C with OpenMPI

make and makefile CS 211

Practical C Issues:! Preprocessor Directives, Multi-file Development, Makefiles. CS449 Fall 2017

Introduction to PICO Parallel & Production Enviroment

CMPSC 311- Introduction to Systems Programming Module: Build Processing

OpenMP - Introduction

Hybrid Model Parallel Programs

Parallel Computing: Overview

Parallel Programming. Libraries and implementations

The make utility. Alark Joshi COMPSCI 253

Lecture 2: Introduction to OpenMP with application to a simple PDE solver

Transcription:

Tutorial: Compiling, Makefile, Parallel jobs Hartmut Häfner Steinbuch Centre for Computing (SCC) Funding: www.bwhpc-c5.de

Outline Compiler + Numerical Libraries commands Linking Makefile Intro, Syntax (Explicit + Implicit Rules...) Parallelising Batch jobs for OpenMP, MPI, Hybrid 2

1. Compilation 3

source (.c) Object files executable (.x) Example: $ gcc o exec.x src1.c src2.c src3.c $./exec.x 4

source (.c) Object files executable (.x) compiling linking objects (.o) $ gcc c src1.c; gcc c src2.c; gcc c src3.c $ gcc o exec.x src1.o src2.o src3.o Changes in a single file do not afford the compilation of all source code. 5

Include files Header files (.h) Declaration of variables Definition of static variables Declaration of functions/subroutines.. Example: include header file /home/myincs/header.h Preprocessor directive in source code: #include "header.h" Add header directory I<include_directory> $ gcc I/home/myincs c src1.c; gcc c src2.c $ gcc o exec.x src1.o src2.o $./exec.x src1.c '#' does not initiate command lines but preprocessor directives in C/C++ code! 6

Example: Hello Main Program #include "hello.h" int main(void){ print_hello(); return 0; } hello.c Header (Declarations) #ifndef _HELLO_H_ #define _HELLO_H_ int print_hello(void); #endif hello.h Functions (Definitons) #include <stdio.h> int print_hello(void){ printf( hello!\n ); return 0; } hello_fct.c Exercise: hello Build objects hello.o hello_fct.o Build executable by linking objects $./hello 7

Shared object files and Libraries Objects can be used by different executables. A library contains program parts (subroutines, classes, type definitions, ) that can be used by different executables. Static library Linked during building executable Shared library Loaded during runtime 8

Shared Object files and Libraries executable (.x) objects (.o) library (.so) library (.so) + + Example: shared library /opt/bwhpc/common/mpi/openmpi/ 2.0.1 intel 16.0/lib/libmpi.so Build executable with (own) static library: Add library directory L<library_directory> load library l<library_name> after refering source/object files $ gcc o exec.x src1.o src2.o L/home/mylibs lexample Run executable: $./exec.x 9

Module files Module files set/prepare following environment variables amongst others: *_LIB_DIR = <library_directory> *_INC_DIR = <include_directory> ${LD_LIBRARY_PATH} Show module file setup with $ module show <module_file> Example: link (shared) MPI library Build executable: $ module load mpi/openmpi # Intel Compiler will be loaded # automatically $ mpicc o hello_mpi hello_mpi.c Run executable: $ mpirun np 4 hello_mpi 10

2. Makefile 11

Motivation Interactively $ gcc o hello I. hello.c hello_fct.c Works as long as command history is active Shell script $./compile.sh Does always recompile the whole code Makefile $ make better organisation of code compilation recompiles only updated files, make: `hello' is up to date. 12

Makefile $ make [<target>] executes script named Makefile or makefile without argument first rule in Makefile is executed Rule definition (format): target: prerequisites <TAB>command Only works with beginning tab stop! Rule has to be applied, if any of these files is changed To apply the rule, command has to be executed. Exercise: Makefile.1 hello: hello.h hello.c hello_fct.c gcc o hello I. hello.c hello_fct.c Makefile.1 define a second rule named clean to remove the executable 13

Rules - Content Explicit rules hello.o: rule to build target hello.o Wildcards hello: *.c hello depends on all files with suffix.c in this directory Pattern rules %.o: rule for all files with suffix.o %.o: %.c % in prerequisites substitutes the same as % in the target Phony Targets.PHONY: clean target clean is nothing to build clean: 14

Variables Variable assignment = recursively expanded (referenced by reference) := simply expanded (referenced by value)?= only if variable is not defined yet (no overwrite) += add item to variable array CC CFLAGS INC OBJ OBJ EXE?= gcc = I. := hello.h := hello.o += hello_fct.o := hello ${EXE}: ${INC} ${OBJ} ${CC} o ${EXE} ${CFLAGS} ${OBJ} Exercise: Makefile.2 hello.o depends on hello.h write an appropriate rule.phony: clean clean: rm f ${OBJ} ${EXE} Makefile.2 15

Automatic Variables Automatic variables change from rule to rule $@ = target $< = first item of prerequisites $^ = all items of prerequisites separated by ' ' CC CFLAGS INC OBJ OBJ EXE?= gcc = I. := hello.h := hello.o += hello_fct.o := hello Exercise: Makefile.3 Use automatic variables in rule to build hello %.o: %.c ${INC} ${CC} o $@ ${CFLAGS} c $< hello: hello.o hello_fct.o ${CC} o ${EXE} ${CFLAGS} ${OBJ}.PHONY: clean clean: rm f ${OBJ} ${EXE} Makefile.3 16

Directives Conditions can be expressed by directives if VAR is (not) defined ifdef/ifndef VAR.. else.. endif if A and B are (not) equal ifeq/ifneq (A,B).. else.. endif Example: Conditional assignment CC?= gcc is equivalent to ifndef CC CC = gcc endif 17

Parts of Makefile can be outsourced e.g. platform specific statements Include External makefile code, e.g. file make.inc, can be loaded in Makefile via include make.inc Exercise: hello_omp make.inc.gnu and make.inc.intel contain compiler specific makefile statements Adjust Makefile.4: include make.inc depending on ${CC} CC = gcc CFLAGS = I. fopenmp make.inc.gnu CC = icc CFLAGS = I. openmp $ module load compiler/gnu $ make $ module load compiler/intel $ make include make.inc.gnu make.inc.intel hello_omp:hello_omp.o ${CC} o $@ ${CFLAGS} $< Makefile.4 18

3. Parallel jobs 19

Submitting serial jobs via script Example: requesting one CPU and 3000 MB of main memory for 5 minutes to run the sequential program hello #!/bin/bash #MSUB -l nodes=1:ppn=1 #MSUB -l walltime=0:05:00 #MSUB -l mem=3000mb #MSUB -q singlenode #MSUB -N serial-test #MSUB -m bea #MSUB -M me@provider.de./hello #sleep 60 Interpreter Submitting the script 01_jobuc.sh with MOAB: $ msub 01_jobuc.sh Header with msub options resource requirements queue definition notification options,... Execution part 20 Tutorial Compiling, Makefiles, Parallel jobs

Submitting parallel jobs (MPI) $ module load mpi/impi $ mpicc o hello_mpi hello_mpi.c #!/bin/bash #MSUB -l nodes=1:ppn=2 #MSUB -l walltime=00:03:00 #MSUB -l pmem=1000mb #MSUB -l advres=workshop.8 #MSUB -N hello_mpi module load mpi/impi mpirun./hello_mpi #sleep 60 (For computations on more than 1 node use queue multinode!) The corresponding MPI module has to be loaded on the compute nodes. Use mpirun to execute the binary. 21 Tutorial Compiling, Makefiles, Parallel jobs

Submitting parallel jobs (OpenMP) $ icc qopenmp o hello_omp hello_omp.c #!/bin/bash #MSUB -l nodes=1:ppn=8 #MSUB -l walltime=00:05:00 #MSUB -l pmem=1000mb #MSUB -q singlenode #MSUB -N hello_omp Shared memory restricts to 1 node. EXECUTABLE=./hello_omp export OMP_NUM_THREADS=${MOAB_PROCCOUNT} echo "Executable ${EXECUTABLE} running with ${OMP_NUM_THREADS} threads" ${EXECUTABLE} Do not define number of threads explicitely. Use MOAB variables. 22 Tutorial Compiling, Makefiles, Parallel jobs

#!/bin/bash #MSUB -l nodes=2:ppn=16 #MSUB -l walltime=0:05:00 #MSUB -l pmem=1000mb #MSUB -q multinode #MSUB -v EXE=./hello_mpi_omp #MSUB -v OMP_NUM_THREADS=2 #MSUB -N hello_mpi_omp #MSUB -o $(JOBNAME).o$(JOBID) module load mpi/openmpi Hybrid Parallel Jobs (OpenMP+MPI) export NTASKS=$((${MOAB_PROCCOUNT}/${OMP_NUM_THREADS})) echo "Executable ${EXE} running on ${MOAB_PROCCOUNT} cores with ${NTASKS} tasks and ${OMP_NUM_THREADS} threads" mpirun -n ${NTASKS} --bind-to core --map-by node:pe=${omp_num_threads} ${EXE} Explicit declaration of task and thread numbers is required 23 Tutorial Compiling, Makefiles, Parallel jobs

A very brief overview on OpenMPI OpenMP is an easy, portable and incremental specification for node-level parallelisation Thread-based, shared memory, single-node (in contrast to MPI) How does it work? Annotate the C/C++/FORTRAN source code with pragmas The compiler transparently generates the necessary code Non-parallel blocks are only executed by the main thread Parallel blocks are handed to a team-of-threads and executed in parallel If the compiler has no support for OpenMP, or if you do not activate OpenMP, the pragmas will be ignored, the code will only run on a single core and still yield the correct result 24

Core syntax Most OpenMP pragmas apply to a structured block or parallel region A single instruction, or A number of statements with a single entry point at the top and a single exit at the bottom #pragma omp parallel { // statements }!$omp parallel // statements!$omp end parallel Only statements inside a block marked with the parallel clause will be executed in parallel It is allowed to abort the execution of the whole application within a structured block 25