Pattern Programming Seeds Framework Notes on Assignment 1 PP-2.1 ITCS 4/5145 Parallel Programming UNC-Charlotte, B. Wilkinson, 2012. August 30, 2012 PatternProg-2.

Slides:



Advertisements
Similar presentations
Toward using higher-level abstractions to teach Parallel Computing 5/20/2013 (c) Copyright 2013 Clayton S. Ferner, UNC Wilmington1 Clayton Ferner, University.
Advertisements

1 Short Course on Grid Computing Jornadas Chilenas de Computación 2010 INFONOR-CHILE 2010 November 15th - 19th, 2010 Antofagasta, Chile Dr. Barry Wilkinson.
Dialogs. Displaying Text in a Dialog Box Windows and dialog boxes –Up to this our output has been to the screen –Many Java applications use these to display.
Embarrassingly Parallel Computations Partitioning and Divide-and-Conquer Strategies Pipelined Computations Synchronous Computations Asynchronous Computations.
1 UNC-Charlotte’s Grid Computing “Seeds” framework 1 © 2011 Jeremy Villalobos /B. Wilkinson Fall 2011 Grid computing course. Slides10-1.ppt Modification.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
Java Unit 9: Arrays Declaring and Processing Arrays.
Exercise problems for students taking the Programming Parallel Computers course. Janusz Kowalik Piotr Arlukowicz Tadeusz Puzniakowski Informatics Institute.
MIT AITI 2002 Abstract Classes, Interfaces. Abstract Classes What is an abstract class? An abstract class is a class in which one or more methods is declared,
Pattern Programming Barry Wilkinson University of North Carolina Charlotte CCI Friday Seminar Series April 13 th, 2012.
1 " Teaching Parallel Design Patterns to Undergraduates in Computer Science” Panel member SIGCSE The 45 th ACM Technical Symposium on Computer Science.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Pattern Programming Barry Wilkinson University of North Carolina Charlotte Computer Science Colloquium University of North Carolina at Greensboro September.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Parameters. Overview A Reminder Why Parameters are Needed How Parameters Work Value Parameters Reference Parameters Out Parameters.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
Embarrassingly Parallel Computations Partitioning and Divide-and-Conquer Strategies Pipelined Computations Synchronous Computations Asynchronous Computations.
Computer Science 320 Reduction. Estimating π Throw N darts, and let C be the number of darts that land within the circle quadrant of a unit circle Then,
CSCI-455/552 Introduction to High Performance Computing Lecture 9.
Side effects A side effect is anything that happens in a method other than computing and/or returning a value. Example: public class hello { public int.
How do you do the following? Find the number of scores within 3 points of the average of 10 scores? What kind of a tool do you need? Today’s notes: Include.
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Pattern Programming with the Seeds Framework © 2013 B. Wilkinson/Clayton Ferner SIGCSE 2013 Workshop 31 intro.ppt Modification date: Feb 17,
Java – Methods Lecture Notes 5. Methods All objects, including software objects, have state and behavior. example, a student as an object has name, address,
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
int [] scores = new int [10];
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
Suzaku Pattern Programming Framework (a) Structure and low level patterns © 2015 B. Wilkinson Suzaku.pptx Modification date February 22,
Pattern Programming PP-1.1 ITCS 4/5145 Parallel Programming UNC-Charlotte, B. Wilkinson, August 29A, 2013 PatternProg-1.
Arrays Chapter 7.
Topic: Classes and Objects
Dr. Barry Wilkinson University of North Carolina Charlotte
Methods Chapter 6.
Suzaku Pattern Programming Framework Workpool pattern (Version 2)
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Stencil Pattern A stencil describes a 2- or 3- dimensional layout of processes, with each process able to communicate with its neighbors. Appears in simulating.
Using compiler-directed approach to create MPI code automatically
Lecture 11 C Parameters Richard Gesick.
Type Conversion, Constants, and the String Object
An Introduction to Java – Part I, language basics
All-to-All Pattern A pattern where all (slave) processes can communicate with each other Somewhat the worst case scenario! ITCS 4/5145 Parallel Computing,
Programming with Parallel Design Patterns
Lab. 3 (May 11th) You may use either cygwin or visual studio for using OpenMP Compiling in cygwin “> gcc –fopenmp ex1.c” will generate a.exe Execute :
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.
Pipelined Pattern This pattern is implemented in Seeds, see
© B. Wilkinson/Clayton Ferner SIGCSE 2013 Workshop 31 session2a
Dr. Barry Wilkinson University of North Carolina Charlotte
int [] scores = new int [10];
Introduction to parallelism and the Message Passing Interface
Monte Carlo Methods A so-called “embarrassingly parallel” computation as it decomposes into obviously independent tasks that can be done in parallel without.
Quiz Questions Seeds pattern programming framework
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.
Parallel Techniques • Embarrassingly Parallel Computations
Embarrassingly Parallel Computations
Pattern Programming Seeds Framework Workpool Assignment 1
Quiz Questions Seeds pattern programming framework
Matrix Addition and Multiplication
Exercise 1 : ex1.java Thread Creation and Execution (sleep() and join()) class C extends Thread {   int i;   C(int i) { this.i = i; }   public void run()
Random Numbers while loop
Methods/Functions.
Visibilities and Static-ness
First Semester Review.
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Pattern Programming Seeds Framework Notes on Assignment 1 PP-2.1 ITCS 4/5145 Parallel Programming UNC-Charlotte, B. Wilkinson, August 30, 2012 PatternProg-2

Seeds Workpool DiffuseData, Compute, and GatherData Methods PP-2.2 DiffuseData DataMap d Returns d to each slave DataMap d created in diffuse DataMap output created in compute DataMap output GatherData Private variable total (answer) Compute DataMap input Data argument data Data argument dat Master Slaves Note DiffuseData, Compute and GatherData methods start with a capital letter although method names should not!

DataMap methods put (String, data) – puts data into DataMap identified by string get (String, data) – gets stored data identified by string In the pi code, data is a Long. DataMap extends Java HashMap which implement a Map, see PP-2.3 Data and DataMap classes For implementation convenience two classes: Data class used to pass data between master and slaves Uses a “segment” number to keep track of packets as they go from one method to another. DataMap class inside compute method DataMap is a subclass of Data and so allows casting.

public Data DiffuseData (int segment) { DataMap d =new DataMap (); input Data = …. d.put(“name_of_inputdata", inputData); return d; } public Data Compute (Data data) { DataMap input = (DataMap )data; //data produced by DiffuseData() DataMap output = new DataMap (); //output returned to gatherdata inputData = input.get(“name_of_inputdata”); … // computation output.put("name_of _results", results); // to return to GatherData() return output; } public void GatherData (int segment, Data dat) { DataMap out = (DataMap ) dat; outdata = out.get (“name_of_results”); result … // aggregate outdata from all the worker nodes. result a private variable } PP-2.4 By framework segment used by Framework to keep track of where to put results GatherData gives back Data object with a segment number Data cast into a DataMap

Other methods called by framework public void initializeModule(String[] args) { Node.getLog().setLevel(Level.WARNING); // reduce logging verbosity … // initialize private variables datacount = … ; } public int getDataCount() { //Set to number of data items to be processed. return datacount; } PP-2.5

Framework methods used in Bootstrapping class Seeds methods start //starts framework, deploy nodes on list of servers startPattern // starts seeds pattern waitOnPattern// waits for pattern to complete stop//stops framework PP-2.6

User methods used in Bootstrap class Additional methods can be specified by programmer in the Workpool class and can be invoked in the Bootstrap class. Typically a method is invoked that produces the final result. Example public double getPi() { // returns value of pi based all workers double pi = (total / (random_samples * DoubleDataSize)) * 4; return pi; } PP-2.7

Question Will a class field modified in the DiffuseData or GatherData methods be updated with the same values as in the Compute method? Answer PP-2.8 NO. The two methods are running on different JVMs (and different nodes)

Monte Carlo Methods A so-called “embarrassingly parallel” computation as it decomposes into obviously independent tasks that can be done in parallel without any into task communications during the computation. Monte Carlo methods use random selections. For parallelizing Monte Carlo code, must address best way to generate random numbers in parallel. 3.15

Circle formed within a 2 x 2 square. Ratio of area of circle to square given by: Points within square chosen randomly. Score kept of how many points happen to lie within circle. Fraction of points within circle will be, given sufficient number of randomly selected samples. 3.16

One quadrant can be described by integral: Random pairs of numbers, (xr,yr) generated, each between 0 and 1. Counted as in circle if 3.18

Alternative (better) Monte Carlo Method Generate random values of x to compute f(x) Sum values of f(x): where x r are randomly generated values of x between x 1 and x 2. Monte Carlo method very useful if the function cannot be integrated numerically (maybe having a large number of variables) 3.19

public Data DiffuseData (int segment) { DataMap d =new DataMap (); d.put("seed", R.nextLong()); return d; // returns a random seed for each job unit } PP-2.13 DiffuseData Method (Required to be implemented) Seeds Monte Carlo code MonteCarloPiModule.java

public Data Compute (Data data) { DataMap input = (DataMap )data; DataMap output = new DataMap (); Long seed = (Long) input.get("seed"); // get random seed Random r = new Random(); r.setSeed(seed); Long inside = 0L; for (int i = 0; i < DoubleDataSize ; i++) { double x = r.nextDouble(); double y = r.nextDouble(); double dist = x * x + y * y; if (dist <= 1.0) { ++inside; } output.put("inside", inside); // to return to GatherData() return output; } PP-2.14 Compute Method (Required to be implemented)

public void GatherData (int segment, Data dat) { DataMap out = (DataMap ) dat; Long inside = (Long) out.get("inside"); total += inside; // aggregate answer from all the worker nodes. } PP-2.15 GatherData Method (Required to be implemented)

getDataCount Method (Required to be implemented) public int getDataCount() { return random_samples; } PP-2.16

Method to compute  result (used in bootstrap module) public double getPi() { // returns value of pi based on all workers double pi = (total / (random_samples * DoubleDataSize)) * 4; return pi; } PP-2.17

Bootstrap class RunMonteCarloPiModule.java package edu.uncc.grid.example.workpool; import java.io.IOException; import net.jxta.pipe.PipeID; import edu.uncc.grid.pgaf.Anchor; import edu.uncc.grid.pgaf.Operand; import edu.uncc.grid.pgaf.Seeds; import edu.uncc.grid.pgaf.p2p.Types; public class RunMonteCarloPiModule { public static void main(String[] args) { try { MonteCarloPiModule pi = new MonteCarloPiModule(); Seeds.start( args[0], false); PipeID id = Seeds.startPattern( new Operand( (String[])null, new Anchor( args[1], Types.DataFlowRoll.SINK_SOURCE), pi ) ); System.out.println(id.toString() ); Seeds.waitOnPattern(id); System.out.println( "The result is: " + pi.getPi() ) ; Seeds.stop(); } catch (SecurityException e) { … } PP-2.18 Deploys framework and runs code

Another Seeds Workpool example Matrix Addition C = A + B Matrices (2-D arrays) A, B, and C. Given elements of A as a i,j and elements of B as b i,j, each element of C is computed as: PP-2.19 (Assignment Task 4 asks you to do matrix multiplication)

MatrixAddModule.java package edu.uncc.grid.example.workpool; import … public class MatrixAddModule extends Workpool { private static final long serialVersionUID = 1L; int[][] matrixA; int[][] matrixB; int[][] matrixC; public MatrixAddModule() { matrixC = new int[3][3]; } public void initMatrices(){ matrixA = new int[][]{{2,5,8},{3,4,9},{1,5,2}}; matrixB = new int[][]{{2,5,8},{3,4,9},{1,5,2}}; } public void initializeModule(String[] args) { Node.getLog().setLevel(Level.WARNING); } PP-2.20 Continues on several sides

public Data DiffuseData(int segment) { int[] rowA = new int[3]; int[] rowB = new int[3]; DataMap d =new DataMap (); int k = segment; for (int i=0;i<3;i++) { //Copy one row of A and one row of B into d rowA[i] = matrixA[k][i]; rowB[i] = matrixA[k][i]; } d.put("rowA",rowA); d.put("rowB",rowB); return d; } PP-2.21 Note use of segment variable

public Data Compute(Data data) { int[] rowC = new int[3]; DataMap input = (DataMap )data; DataMap output = new DataMap (); int[] rowA = (int[]) input.get("rowA"); int[] rowB = (int[]) input.get("rowB"); for (int i=0;i<3;i++){ //computation rowC[i] = rowA[i] + rowB[i]; } output.put("rowC",rowC); return output; } PP-2.22 This is the part that will need altering in the assignment to achieve multiplication

public void GatherData(int segment, Data dat) { DataMap out = (DataMap ) dat; int[] rowC = (int[]) out.get("rowC"); for (int i=0;i<3;i++) { matrixC[segment][i]= rowC[i]; } public void printResult(){ for (int i=0;i<3;i++){ System.out.println(""); for(int j=0;j<3;j++){ System.out.print(matrixC[i][j] + ","); } public int getDataCount() { return 3; } PP-2.23 Note use of segment variable

Bootstrap class - RunMatrixAddModule.java package edu.uncc.grid.example.workpool; import … public class RunMatrixAddModule { public static String localhost = "T5400"; public static String seedslocation = "C:\\seeds_2.0\\pgaf"; public static void main (String [] args ) { try{ Seeds.start( seedslocation,false); MatrixAddModule m = new MatrixAddModule(); m.initMatrices(); PipeID id = Seeds.startPattern(new Operand ((String[])null,new Anchor (localhost, Types.DataFlowRoll.SINK_SOURCE),m)); Seeds.waitOnPattern(id); m.printResult(); Seeds.stop(); … PP-2.24 In this example, host and path to Seeds are hardcoded.

Measuring Time (Task 4 in Assignment 1) Can instrument code in the bootstrap class: public class RunMyModule { public static void main (String [] args ) { try{ long start = System.currentTimeMillis(); MyModule m = new MyModule(); Seeds.start(. ); PipeID id = ( … ); Seeds.waitOnPattern(id); Seeds.stop(); long stop = System.currentTimeMillis(); double time = (double) (stop - start) / ; System.out.println(“Execution time = " + time); } catch (SecurityException e) { … … PP-2.25

New version of Seeds Just done by Jeremy Multicore version Apparently much faster on a multicore platform Does not use JXTA P2P network to run cluster nodes, thread based. Bootstrap class does not need to start and stop JXTA P2P. Seeds.start() and Seeds.stop() not needed. Otherwise user code similar. I have not yet tested it, but hopefully will be able to get to class soon. PP-2.26 public class RunMonteCarloPiModule { public static void main(String[] args) { try { MonteCarloPiModule pi=new MonteCarloPiModule(); Thread id = Seeds.startPatternMulticore( new Operand( (String[])null, new Anchor( args[0], Types.DataFlowRole.SINK_SOURCE), pi ), 4 ); id.join(); System.out.println( "The result is: " + pi.getPi() ) ; } catch (SecurityException e) { … }

Questions 27