Suzaku Pattern Programming Framework Workpool pattern (Version 2)

Slides:



Advertisements
Similar presentations
Practical techniques & Examples
Advertisements

1 CS 162 Introduction to Computer Science Chapter 7 Matrix Manipulation Herbert G. Mayer, PSU Status 9/21/2014.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
CMPUT 101 Lab #6 October 29, :00 – 17:00. Array in C/C++ Array is a structure type variable. One dimension of array int: int num[3]; There are.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Programming Arrays. Question Write a program that reads 3 numbers from the user and print them in ascending order. How many variables do we need to store.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Arrays. Collections We would like to be able to keep lots of information at once Example: Keep all the students in the class Grade each one without writing.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
Suzaku Pattern Programming Framework (a) Structure and low level patterns © 2015 B. Wilkinson Suzaku.pptx Modification date February 22,
ITCS 4/5145 Parallel Computing, UNC-Charlotte, B
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
The Suzaku Pattern Programming Framework 6th NSF/TCPP Workshop on Parallel and Distributed Computing Education (EduPar-16) 2016 IEEE International Parallel.
Arrays Chapter 7.
Functions Students should understand the concept and basic mechanics of the function call/return pattern from CS 1114/2114, but some will not. A function.
Computer Science 210 Computer Organization
The Suzaku Pattern Programming Framework
Command Line Arguments
Lecture-5 Arrays.
MPI Message Passing Interface
Introduction to OpenMP
Multi-dimensional Array
Module 2 Arrays and strings – example programs.
Case Study 2 – Marking a Multiple-choice Test
Arrays and Pointers CSE 2031 Fall September 2018.
2011/11/20: Lecture 15 CMSC 104, Section 4 Richard Chang
Computer Science 210 Computer Organization
Command Line Arguments
CS1100 Computational Engineering
Using compiler-directed approach to create MPI code automatically
Array Data Structure B.Ramamurthy 11/21/2018 B.Ramamurthy.
ITCS 4/5145 Parallel Computing, UNC-Charlotte, B
Functions, Part 1 of 3 Topics Using Predefined Functions
CS111 Computer Programming
B. Wilkinson/Clayton Ferner Seeds.ppt Modification date August
Pipeline Pattern ITCS 4/5145 Parallel Computing, UNC-Charlotte, B. Wilkinson, 2012 slides5.ppt Oct 24, 2013.
Quiz Questions Suzaku pattern programming framework
Pattern Programming Tools
© B. Wilkinson/Clayton Ferner SIGCSE 2013 Workshop 31 session2a
ITCS 4/5145 Parallel Computing, UNC-Charlotte, B
Quiz Questions Seeds pattern programming framework
Multidimensional array
Programming with Shared Memory
Arrays Week 2.
Pipeline Pattern ITCS 4/5145 Parallel Computing, UNC-Charlotte, B. Wilkinson, 2012 slides5.ppt March 20, 2014.
Pipeline Pattern ITCS 4/5145 Parallel Computing, UNC-Charlotte, B. Wilkinson slides5.ppt August 17, 2014.
Using compiler-directed approach to create MPI code automatically
7 Arrays.
Functions, Part 1 of 3 Topics Using Predefined Functions
Lets Play with arrays Singh Tripty
Pattern Programming Seeds Framework Workpool Assignment 1
Patterns Paraguin Compiler Version 2.1.
Functions continued.
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Arrays Arrays A few types Structures of related data items
Quiz Questions Seeds pattern programming framework
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Arrays.
Arrays.
In this class, we will cover:
Matrix Addition and Multiplication
Pointers and dynamic objects
Functions, Part 1 of 3 Topics Using Predefined Functions
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
ICS103: Programming in C Searching, Sorting, 2D Arrays
MPI Message Passing Interface
Presentation transcript:

Suzaku Pattern Programming Framework Workpool pattern (Version 2) © 2016 B. Wilkinson SuzakuWorkpool.pptx Modification date: February 25, 2016

Suzaku Workpool version 2 Mirrors the Java-based Seeds framework interface (see later) but using C but without objects. In Seeds, a Java hashmap used that associates a key (a string) with each data item. Programmer refers to data by the key and uses put method to add data to the task and get method to extract data. Now not limited to just 1-D arrays of doubles. May incur a greater overhead that version 1 but more elegant to use and will be basis of the dynamic workpool (Workpool version 3) and other patterns.

Suzaku Put and Get SZ_Put(char[8] key, void *x) Purpose: Places data into the send message and associates a user-defined name to it. SZ_Get(char[8] key, void *x) Purpose: Extract data from the received message that is associated with a user-defined name. x can be an individual character, integer, double, or 1-D array of characters, integers, or doubles, or a multi-dimensional array of doubles. Type does not have to be specified. Multi-dimensional arrays of other types not supported. Implemented with macros calling routines.

Test Program using Suzaku workpool version 2 #include <stdio.h> #include "suzaku.h" #define T 4 // number of tasks, max = INT_MAX - 1 void init(int *tasks) { // sets number of tasks *tasks = T; return; } void diffuse(int taskID) { int j; char w[] = "Hello World"; static int x = 1234; // only initialized first time function called static double y = 5678; double z[2][3]; z[0][0] = 357; z[1][1] = 246; SZ_Put("w",w); SZ_Put("x",&x); SZ_Put("y",&y); SZ_Put("z",z); printf("Diffuse Task sent: taskID = %2d, w = %s, x = %5d, y = %8.2f, z[0][0] = %8.2f, z[1][1] = %8.2f\n",taskID, w, x, y,z[0][0],z[1][1]); x++; y++;

void compute(int taskID) { // simply passing data x 10 in different order char w[12] = "-----------"; int x = 0; double y = 0; double z[2][3]; z[0][0] = 0; z[1][1] = 0; SZ_Get("z",z); SZ_Get("x",&x); SZ_Get("w",w); SZ_Get("y",&y);   printf("Compute Task received: taskID = %2d, w = %s, x = %5d, y = %8.2f, z[0][0] = %8.2f, z[1][1] = %8.2f\n",taskID, w, x, y,z[0][0],z[1][1]); x = x * 10; y = y * 10; z[0][0] = z[0][0] * 10; z[1][1] = z[1][1] * 10; printf("Compute Result: taskID = %2d, w = %s, x = %5d, y = %8.2f, z[0][0] = %8.2f, z[1][1] = %8.2f\n",taskID, w, x, y,z[0][0],z[1][1]); SZ_Put("xx",&x); // use different names for test, could have been same names SZ_Put("yy",&y); SZ_Put("zz",z); SZ_Put("ww",w) return; }

char w[12] = "-----------"; int x = 0; double y = 0; double z[2][3]; void gather(int taskID) { // function done by master collecting slave results. char w[12] = "-----------"; int x = 0; double y = 0; double z[2][3]; z[0][0] = 0; z[1][1] = 0;   SZ_Get("ww",w); SZ_Get("zz",z); SZ_Get("xx",&x); SZ_Get("yy",&y); printf("Gather Task received: taskID = %2d, w = %s, x = %5d, y = %8.2f, z[0][0] = %8.2f, z[1][1] = %8.2f\n",taskID, w, x, y,z[0][0],z[1][1]); return; } Note order of put and get are not the same although they could be. Names used to identify variables chosen by programmer. (They are limited to eight characters in the current implementation for simplicity.)

int main(int argc, char *argv[]) { int i; // All variables declared here are in every process int P; // number of processes, set by SZ_Init(P)   SZ_Init(P); // initialize MPI message-passing environment // sets P to be number of processes printf("number of tasks = %d\n",T); SZ_Parallel_begin SZ_Workpool2(init,diffuse,compute,gather); SZ_Parallel_end; // end of parallel SZ_Finalize(); return 0; }

Sample output

Matrix multiplication Here each task consists of multiplying one row of A with one column of B to create one element of the answer

Mapping rows and columns to tasks Assuming 3 x 3 arrays: Arow Bcol task 0 0 0 task 1 0 1 task 2 0 2 task 3 1 0 task 4 1 1 task 5 1 2 task 6 2 0 task 7 2 1 task 8 2 2 int Arow = taskID/3; Int Bcol = taskID%3;

#include <stdio. h> #include "suzaku #include <stdio.h> #include "suzaku.h" #define T 9 // required Suzaku constant, number of tasks, max = INT_MAX - 1 #define N 3 // size of matrices double A[N][N], B[N][N], C[N][N], Cseq[N][N]; void init(int *tasks) { *tasks = T; return; } void diffuse(int taskID) { // as Seeds sample but inefficient copying arrays int i; int a, b; double rowA[3],colB[3]; a = taskID / N; // taskID used in computation b = taskID % N; for (i = 0; i < N; i++) { //Copy one column of B into output colB[i] = B[i][b]; // do not need to copy row of A SZ_Put("rowA",A[a]); SZ_Put("colB",colB);

void compute(int taskID) { int i; double out; double rowA[3],colB[3]; SZ_Get("rowA",rowA); SZ_Get("colB",colB); out = 0; for (i = 0; i < N; i++) { out += rowA[i] * colB[i]; } SZ_Put("out",&out); return;

void gather(int taskID) { int a,b; double answer; SZ_Get("out",&answer); a = taskID / 3; b = taskID % 3; C[a][b]= answer; return; }

int main(int argc, char *argv[]) { int i; // All variables declared here are in every process int P; // number of processes, set by SZ_Init(P) double time1, time2; // for timing SZ_Init(P); // initialize MPI environment, sets P to number of processes initialize(); // initialize input arrays … // print arrays … // compute matrix multiplication sequentially for testing time1 = SZ_Wtime(); // record time stamp SZ_Parallel_begin // start of parallel section SZ_Workpool2(init,diffuse,compute,gather); SZ_Parallel_end; // end of parallel time2 = SZ_Wtime(); // record time stamp … // print results printf("Elapsed_time = %f (seconds)\n", time2 - time1); SZ_Finalize(); return 0; }

Questions