Download presentation
Presentation is loading. Please wait.
1
ParaFlow A practical, easy to use, parallel processing language.
2
Parallel programming constructs: Para: executes in parallel on all items in a collection. Flow: marks a function as having no side effects.
3
Simplicity No objects or even functions are required. Hello world program is just: –print(“Hello world.”); Built in string type is easy and powerful. Memory for strings and objects is automatically freed. Files are automatically closed. Syntax is simple and readable. Generally very like C or Java. No threads to synchronize.
4
Example Flow Function flow polar(double angle,rad) into (double x,y) { x = rad * math.cos(angle); y = rad * math.sin(angle); } (double a,r) = polar(4.0, 5.0); // The compiler would report an error if // the polar function modified any // global variables since it is declared as // “flow”. Functions with side effects must be // declared with the “to” keyword instead.
5
Para expression constructs // Make an array to work on. array of int a = (1,2,3,4,5,6); // Get array of all elements squared array of int aSquared = para (x in a) get x*x; // Get maximum value in array int maxA = para (x in a) max x; // Get array just containing odd numbers array of int odd = para (x in a) filter x&1;
6
The para…do construct // Declare a 2-D point class class point {double x,y;} // function to scale an array of points to blowUp(array of point points, double scaleFactor) { // With the para … do construct can alter // all elements in a collection in parallel. para (p in points) do { p.x *= scaleFactor; p.y *= scaleFactor; }
7
The case statement // The case is different from C’s switch case (name) { “Mark”,”Angie” : occupation = “programmer”; “Heidi” : occupation = “writer”; “Rover” : { occupation = “dog”; print(“Woof”); } else : occupation = “unknown”; } // Motivation for difference is to avoid problems // with missing breaks, and allow use of non-integer // expressions.
8
Object Oriented Features Classes with single inheritance. Interfaces similar to Java. Automatic serialization of objects No overloading (but default parameters allowed). Methods must be declared polymorphic to be overridden.
9
A Simple Class and Serialization class family { string name; array of string members; } family kents = (“Kent”, (“Mira”, “Tisa”, “Jim”, “Heidi)); print(kents); > (“Kent”, (“Mira”, “Tisa”, “Jim”, “Heidi”)) print(kents.members.size) > 4
10
Other Advanced Features Flexible quotes makes embedding HTML and other intricate text in program easy. Does variable substitution in strings. Bounds checking on array accesses, and checking for use of uninitialized objects. Errors generate stack trace and position of error in source. For statement operates over collections (and makes bounds checks unneeded). Traditional for (;;) also supported. No need to predeclare functions or for separate header files. Built in dir (aka hash,directory) collection. No need to cast objects out of collections.
11
Printing HTML fragment string title = “My ParaFlow CGI Program $programName”; string background = “images/gears.jpg”; print(quote to ENDOFHTML $title BACKGROUND=“$background”> Hello HTML CGI World from ParaFlow ENDOFHTML);
12
Example Dir and For dir of int numNames = (“one” @ 1, “two” @ 2, “three” @ 3) print(numNames[“one”]); 1 for (i in numNames) print( i + “ “ + i*i); 1 1 2 4 3 9 for (key@val in numNames) print(“$key -> $val); one -> 1 two -> 2 three-> 3
13
Run Time Errors to goTooFar(array of int a, int value) // Set all elements of a to a value with a bug { for (int i=0; i<= a.size; i++) a[i] = value; } to initArrays(array of int a, int aVal, string why) // Initialize two arrays to values { print(“Initializing a and b because $why”); goTooFar(a,aVal); } array[10] of int a; initArrays(a,123,”just because”); Initializing a because just because -------- start stack dump -------- goTooFar(a:, value:123) initArrays(a:, aVal:123, why:”just because”) Run time error line 5 col 4 of pastEnd.pf: array access out of bounds
14
More complex classes class animal { string name; to printName() {print(self.name);} polymorphic to speak() {print(“???”); } } class dog extends animal { polymorphic to speak() {print(“bark”); } } class toyPoodle extends dog { polymorphic to speak() {print(“yip”); } } dog fido = (“Fido”), toyPoodle fifi = (“Fifi”); array of animals = (fido, fifi) foreach (a in animals) a.speak(); >bark >yip
15
What’s Implemented Classes with inheritance & polymorphism Print and file I/O that handles objects of different types without being told how. For, while, if, case, functions with multiple returns Modules, exceptions, interfaces String, file, html fetch libraries. Reference counting/auto freeing of objects Serial implementations of “para” constructs.
16
Still to come Making parallel constructs actually work in parallel. Generating Pentium rather than C code. –Current code is about 1/4 speed of equivalent C Generating Open Source buzz on language –Open Source Conf Portland in July is launch
17
Implementation Whole module done in memory in many passes: –Tokenizer –Scan tokens for class names –Parser –Resolving variable names –Type checker –C code generator Calls gcc on C code.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.