Cilk CISC 879 Parallel Computation Erhan Atilla Avinal.

Slides:



Advertisements
Similar presentations
Multi-core Computing Lecture 3 MADALGO Summer School 2012 Algorithms for Modern Parallel and Distributed Models Phillip B. Gibbons Intel Labs Pittsburgh.
Advertisements

© 2009 Charles E. Leiserson and Pablo Halpern1 Introduction to Cilk++ Programming PADTAD July 20, 2009 Cilk, Cilk++, Cilkview, and Cilkscreen, are trademarks.
MPI Message Passing Interface
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
Cilk NOW Based on a paper by Robert D. Blumofe & Philip A. Lisiecki.
U NIVERSITY OF M ASSACHUSETTS, A MHERST – Department of Computer Science The Implementation of the Cilk-5 Multithreaded Language (Frigo, Leiserson, and.
CILK: An Efficient Multithreaded Runtime System. People n Project at MIT & now at UT Austin –Bobby Blumofe (now UT Austin, Akamai) –Chris Joerg –Brad.
Parallelizing Incremental Bayesian Segmentation (IBS) Joseph Hastings Sid Sen.
Parallelizing C Programs Using Cilk Mahdi Javadi.
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
Big Picture Lab 4 Operating Systems Csaba Andras Moritz.
C Review Pointers, Arrays, and I/O CS61c Summer 2006 Michael Le.
Image Processing Using Cilk 1 Parallel Processing – Final Project Image Processing Using Cilk Tomer Y & Tuval A (pp25)
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
15213 C Primer 17 September Outline Overview comparison of C and Java Good evening Preprocessor Command line arguments Arrays and structures Pointers.
Concurrency 1 CS502 Spring 2006 Thought experiment static int y = 0; int main(int argc, char **argv) { extern int y; y = y + 1; return 0; }
Contemporary Languages in Parallel Computing Raymond Hummel.
CS470/570 Lecture 5 Introduction to OpenMP Compute Pi example OpenMP directives and options.
Multithreaded Programming in Cilk L ECTURE 2 Charles E. Leiserson Supercomputing Technologies Research Group Computer Science and Artificial Intelligence.
STRATEGIC NAMING: MULTI-THREADED ALGORITHM (Ch 27, Cormen et al.) Parallelization Four types of computing: –Instruction (single, multiple) per clock cycle.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
1 OpenMP Writing programs that use OpenMP. Using OpenMP to parallelize many serial for loops with only small changes to the source code. Task parallelism.
Semantics CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
Multithreaded Programming in Cilk L ECTURE 3 Charles E. Leiserson Supercomputing Technologies Research Group Computer Science and Artificial Intelligence.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
1 Carnegie Mellon Recitation : Introduction to Computer Systems Recitation 15: December 3, 2012 Daniel Sedra Section C.
Share Memory Program Example int array_size=1000 int global_array[array_size] main(argc, argv) { int nprocs=4; m_set_procs(nprocs); /* prepare to launch.
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
CS333 Intro to Operating Systems Jonathan Walpole.
1 ITCS 6/8010 CUDA Programming, UNC-Charlotte, B. Wilkinson, Jan 25, 2011 Synchronization.ppt Synchronization These notes will introduce: Ways to achieve.
1 Pthread Programming CIS450 Winter 2003 Professor Jinhua Guo.
Lecture 7: POSIX Threads - Pthreads. Parallel Programming Models Parallel Programming Models: Data parallelism / Task parallelism Explicit parallelism.
Chapter 4 Message-Passing Programming. The Message-Passing Model.
P ARALLEL P ROCESSING F INAL P RESENTATION CILK Eliran Ben Moshe Neriya Cohen.
3.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Overview: Process Concept Process Scheduling Operations on Processes.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Software Systems Advanced Synchronization Emery Berger and Mark Corner University.
Thinking in Parallel – Implementing In Code New Mexico Supercomputing Challenge in partnership with Intel Corp. and NM EPSCoR.
Functions & Pointers in C Jordan Erenrich
Synchronization These notes introduce:
C H A P T E R E L E V E N Concurrent Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
What we will cover A crash course in the basics of C “Teach yourself C in 21 days”
Scheduling Multithreaded Computations By Work-Stealing Robert D. Blumofe The University of Texas, Austin Charles E. Leiserson, MIT Laboratory for Computer.
3/12/2013Computer Engg, IIT(BHU)1 OpenMP-1. OpenMP is a portable, multiprocessing API for shared memory computers OpenMP is not a “language” Instead,
Multi-dimensional Arrays and other Array Oddities Rudra Dutta CSC Spring 2007, Section 001.
1 Cilk Chao Huang CS498LVK. 2 Introduction A multithreaded parallel programming language Effective for exploiting dynamic, asynchronous parallelism (Chess.
CS 3013 & CS 502 Summer 2006 Concurrency & Processes1 CS3013 & CS502 Operating Systems.
CILK: An Efficient Multithreaded Runtime System
Introduction to OpenMP
5.13 Recursion Recursive functions Functions that call themselves
CMPS 5433 Programming Models
Prabhanjan Kambadur, Open Systems Lab, Indiana University
Command Line Arguments
CS399 New Beginnings Jonathan Walpole.
Computer Engg, IIT(BHU)
September 4, 1997 Parallel Processing (CS 667) Lecture 5: Shared Memory Parallel Programming with OpenMP* Jeremy R. Johnson Parallel Processing.
Command-Line Arguments
Programmazione I a.a. 2017/2018.
CSE4102/5102 Team Project A Study of Parallel Programming Languages
Multithreaded Programming in Cilk LECTURE 1
Jonathan Walpole Computer Science Portland State University
Govt. Polytechnic,Dhangar
Introduction to CILK Some slides are from:
Dynamic Memory A whole heap of fun….
Introduction to parallelism and the Message Passing Interface
Transactions with Nested Parallelism
Introduction to OpenMP
Cilk A C language for programming dynamic multithreaded applications on shared-memory multiprocessors. Example applications: virus shell assembly graphics.
The Stack.
Cilk and Writing Code for Hardware
Introduction to CILK Some slides are from:
Presentation transcript:

Cilk CISC 879 Parallel Computation Erhan Atilla Avinal

2/21 Introduction What is Cilk ? Multithreaded Computation Language Specifications Cilk Runtime System Compiling & Running

3/21 What is Cilk? A language for multithreaded parallel programming based on C. Effective in highly asynchronous parallelism. No message passing

4/21 Multithreaded Computation Cilk guarantees that programs are scheduled efficiently by its runtime system. Programmer does not deal with message passing.

5/21 int fib (int n) { if (n<2) return (n); else { int x, y; x = fib (n-1); y = fib (n-2); return (x+y); } int main (int argc, char *argv[]) { int n, result; n = atoi(argv[1]); result = fib (n); printf ("Result: %d\n", result); return 0; } #include cilk int fib (int n) { if (n<2) return n; else { int x, y; x = spawn fib (n-1); y = spawn fib (n-2); sync; return (x+y); } cilk int main (int argc, char *argv[]){ int n, result; n = atoi(argv[1]); result = spawn fib(n); sync; printf ("Result: %d\n", result); return 0; }

6/21 Multithreaded Computation

7/21 Spawn Spawns Cilk procedures to start parallel computations int i; float j; cilk int foo(); i= spawn foo(); YES j= spawn foo(); NO x = spawn foo() + spawn bar(); NO

8/21 Shared Memory Cilk supports shared memory Sharing occurs by passing pointers to spawned procedures (call by reference).

9/21 Shared Memory cilk int foo (void) { int x = 0, y; spawn bar(&x); y = x + 1; sync; return (y); } cilk void bar (int *px) { printf("%d", *px + 1); return; } cilk int foo (void) { int x = 0; spawn bar(&x); x = x + 1; sync; return (x); } cilk void bar (int *px) { *px = *px + 1; return; } Data Race

10/21 Locking Cilk_lockvar data type #include : :Cilk_lockvar mylock; : { Cilk_lock_init(mylock); : Cilk_lock(mylock); /* begin critical section */ : Cilk_unlock(mylock); /* end critical section */ }

11/21 Inlets C Functions internal to a Cilk procedure Cannot contain spawn or sync Cilk guarantees that all operations in inlets are atomic

12/21 Inlets cilk int fib (int n) { int x = 0; inlet void summer (int result) { x += result; return; } if (n<2) return n; else { summer(spawn fib (n-1)); summer(spawn fib (n-2)); sync; return (x); }

13/21 SYNCHED Keyword Tests if procedure is synchronized. state1 = alloca(state_size); /* fill in *state1 with data */ spawn foo(state1); if (SYNCHED) state2 = state1; else state2 = alloca(state_size); /* fill in *state2 with data */ spawn bar(state2); sync;

14/21 Aborting “abort” : causes all of the spawned children to abort. Cilk does not guarantee that all children will be aborted instantly.

15/21 Aborting cilk void baz(int n); cilk void foo(int n) { inlet void bar() { abort; } bar(spawn baz(17)); spawn baz(28); sync; }

16/21 Cilk Runtime System(CRS) CRS implements a efficient scheduling policy : work-stealing When a processor runs out of work it steals work from another processor randomly. Deque (Double-Ended Queue)

17/21 Cilk Runtime System(CRS)

18/21 Compiling “cilk” command  supports gcc options  cilk fib.cilk -o fib  cilk -cilk-profile -cilk-critical-path -O2 fib.cilk  -cilk-profile : how much memory is used, how much time each processor spends, etc.

19/21 Compiling “cilk” command  -cilk-critical-path : measures ideal execution time of your program on an infinite number of processors. It may slow down the execution of the program because of many calls to timing routines.

20/21 Running fib --nproc 4 --stats stats : shows performance dataif -cilk- profile is used incompilation. --nproc : number of processors used

21/21 Reading List Cilk Main Page Cilk Reference Manual