+ All Categories
Home > Documents > High Performance Computing

High Performance Computing

Date post: 11-Feb-2016
Category:
Upload: chelsi
View: 25 times
Download: 0 times
Share this document with a friend
Description:
MPI and C-Language Seminars 2010. High Performance Computing. Seminar Plan (1/3). Aim: Introduce the ‘C’ Programming Language. Plan to cover: Basic C, and programming techniques needed for HPC coursework. C-bindings for the Message Passing Interface (MPI). Performance modelling. - PowerPoint PPT Presentation
Popular Tags:
29
HIGH PERFORMANCE COMPUTING MPI and C-Language Seminars 2010
Transcript
Page 1: High Performance Computing

HIGH PERFORMANCE

COMPUTING

MPI and C-Language Seminars 2010

Page 2: High Performance Computing

Seminar Plan (1/3) Aim:

Introduce the ‘C’ Programming Language.

Plan to cover: Basic C, and programming techniques needed for HPC coursework. C-bindings for the Message Passing Interface (MPI). Performance modelling.

We won’t be covering C++ (but many of the skills are transferable).

Page 3: High Performance Computing

Seminar Plan (2/3) Week 1 – Introduction, Data Types, Control Flow, Pointers Week 2 – Arrays, Structures, Enums, I/O, Memory Week 3 – Compiler Options and Debugging

Week 4 – MPI in C and Using the HPSG Cluster

Week 5 – “How to Build a Performance Model”

Week 6-9 – Coursework Troubleshooting(Seminar tutors available in their office)

Page 4: High Performance Computing

Seminar Plan (3/3) The first three weeks focus on developing basic C skills; much

of this will be familiar.

Feel free to skip this if you already feel confident.

Unless you have done this course before, or are on a PhD programme with HPSG, it is a good idea to attend from Week 4 onwards.

Seminars will usually be held on Wednesdays, 11:00 – 12:00.

Page 5: High Performance Computing

Contact Info For C-related queries:

John Pennycook ([email protected])

For performance modelling queries: Oli Perks ([email protected])

Availability: Always on e-mail. High Performance Systems Group (CS 2.04).

Resources: http://go.warwick.ac.uk/ep/pg/csrgai/teaching/cs402

Page 6: High Performance Computing

Books Worth consulting (in the library):

The C Programming Language, (2nd Edition), Kernighan & Ritchie, 1988 C – How to Program, (5th Edition), Deitel, 2006

Online reference book linked at: http://go.warwick.ac.uk/ep/pg/csrgai/teaching/cs402

Page 7: High Performance Computing

Overview of C Much of the Java language builds on C/C++. Some of the

language keywords and behaviour is very similar.

Beware – Though keywords and ‘names’ of types may be similar, they are often different.

Mixing between languages can introduce lots of bugs unless you’re sure what you’re doing.

Page 8: High Performance Computing

Data Types

Page 9: High Performance Computing

Data Types in C There are only four basic data types in C:

1. char – a single byte (8-bits) capable of holding an ASCII character.2. int – an integer value, the size of which is based on the word size of

the machine (often 32-bits).3. float – a single precision floating point number (often 32-bit, IEEE).4. double – a double precision floating point number (often 64-bit, IEEE).

Note:These sizes are the most commonly encountered, but may be different on some platforms (non-Intel/AMD).

Page 10: High Performance Computing

Integers in C (1/2) Two additional qualifiers to control the size of integer values:

1. short int – a ‘shorter’ version of int.2. long int – a ‘longer’ version of int.

Rules: short int <= int <= long int short int >= 16 bits. int >= 16 bits. long int >= 32 bits.

Page 11: High Performance Computing

Integers in C (2/2) Two (more) additional qualifiers for integer types:

1. unsigned – interpret the value as starting from 0.2. signed – allow negative numbers.

Use unsigned to increase the range of values available, provided you are sure negative values will not be required.

Mixing unsigned and signed values can cause bugs, so be careful.

Page 12: High Performance Computing

Booleans in C There is no boolean ‘type’ in C.

Booleans are implemented and evaluated as integer values: TRUE = 1 FALSE = 0

Keywords may not be pre-defined in every implementation of C.

Conversely: 0 = FALSE Non-zero = TRUE

Page 13: High Performance Computing

Arrays in C (1/2) Arrays in C are just allocated contiguous blocks of memory.

For example:

int myarray[5];

allocates space for 5 integers in one contiguous block.

Arrays are not objects, so you cannot access properties (like length). You must record the maximum length of the array.

Page 14: High Performance Computing

Arrays in C (2/2) The name of the array variable can be used as a pointer:

int* pointer = myarray;

myarray is a pointer to the first element in the array.

We will come back to this when we start looking at pointers in more detail...

Page 15: High Performance Computing

Strings in C (1/2) Strings are implemented using an array of characters, but with

an additional element at the end of the string.

Strings must terminate with the null character, ‘\0’.

For example:

“Hello” = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘\0’ }

Page 16: High Performance Computing

Strings in C (2/2) Most important functions are implemented in the string library.

To use the string library, put:

#include <string.h>

at the top of your file.

All string functions in the C libraries will use the ‘\0’ character to detect the end of a string.

Page 17: High Performance Computing

Control Flow

Page 18: High Performance Computing

Control Flow in C (1/2) if, while, do ... while are identical, except that

conditions must produce an integer ‘boolean’ result.

Consider:

if (2 % 2) {...

}

... Will not run, since 2 % 2 = 0.

Page 19: High Performance Computing

Control Flow in C (2/2) for loops are not quite identical.

Depending on the language mode, you may not be able to declare variable inside a for-loop definition:

int i;for (i = 0; i < 10; i++) {

printf(“%d \n”, i);}

Page 20: High Performance Computing

Operators in C Mathematical operators in C are identical to those in Java.

+, -, *, / <=, >=, ==, !=, <, >, &&, || ! % (modulus) &, |

++i, i++, --i, i-- (pre/post-increment/decrement)

Page 21: High Performance Computing

Pointers

Page 22: High Performance Computing

Pointers (1/4) Pointers are references to locations in memory.

They are one of the biggest causes of bugs in software construction.

Worse – they are one of the biggest reasons coursework does not produce correct solutions on marking day.

Page 23: High Performance Computing

Pointers (2/4) To declare a pointer:

int myvalue = 42;int* mypointer;

mypointer = &myvalue;

int* creates a pointer to a location in memory. This is treated as if it were an integer value.

&myvalue is the location of myvalue in memory.

Page 24: High Performance Computing

Pointers (3/4) Remember:

*ptr – look at the address pointed to by ptr. &v – get the address at which v is stored.

Be careful – every year pointers cause problems.The compiler can detect some common bugs, but not all of them... The only way to fix these is to inspect your code manually.

Page 25: High Performance Computing

Pointers (4/4) Common mistakes:

1. Uninitialised PointersThe pointer is not initialised before it is used.An un-initialised pointer has a value of 0 by default.This causes a segmentation fault.

2. Out-of-bounds Memory AccessA pointer is used to access an array, and pushed outside of the array’s bounds.This either corrupts memory or gives a segmentation fault.

Page 26: High Performance Computing

Getting Started

Page 27: High Performance Computing

Hello World Typical “Hello World” program:

#include <stdio.h>

main (int argc, char *argv[]) {printf(“Hello world!\n”);

}

The #include acts like a Java ‘import’ statement.

Page 28: High Performance Computing

Compilation (1/2) To compile a C file to object code:

gcc –c myfile.c

To link object code in an executable:

gcc –o myprogram myfile.o

To run the executable:

./myprogram

Page 29: High Performance Computing

Compilation (2/2) Compilers:

Linux/Mac OS X – gcc Windows – Microsoft Visual C++/Intel C Compiler

Code and seminar contents should work with these compilers (but no promises).

You may not be able to compile the MPI coursework at home unless you compile and install the MPI runtimes.

Your code will be tested running on department machines; it may be best to do your compilation here.


Recommended