cs402 Seminar 1
cs402 Seminar 1
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.
Availability:
Always on e-mail.
High Performance Systems Group (CS 2.04).
Resources:
http://go.warwick.ac.uk/ep/pg/csrgai/teaching/cs402
Books
Worth consulting (in the library):
The C Programming Language, (2nd Edition), Kernighan & Ritchie, 1988
C – How to Program, (5th Edition), Deitel, 2006
Note:
These sizes are the most commonly encountered, but may
be different on some platforms (non-Intel/AMD).
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.
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.
Conversely:
0 = FALSE
Non-zero = TRUE
Arrays in C (1/2)
Arrays in C are just allocated contiguous blocks of memory.
For example:
int myarray[5];
For example:
#include <string.h>
All string functions in the C libraries will use the ‘\0’ character
to detect the end of a string.
Control Flow
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) {
...
}
int i;
for (i = 0; i < 10; i++) {
printf(“%d \n”, i);
}
Operators in C
Mathematical operators in C are identical to those in Java.
+, -, *, /
<=, >=, ==, !=, <, >, &&, ||
!
% (modulus)
&, |
mypointer = &myvalue;
1. Uninitialised Pointers
The pointer is not initialised before it is used.
An un-initialised pointer has a value of 0 by default.
This causes a segmentation fault.
#include <stdio.h>
gcc –c myfile.c
./myprogram
Compilation (2/2)
Compilers:
Linux/Mac OS X – gcc
Windows – Microsoft Visual C++/Intel C Compiler