SlideShare a Scribd company logo
1 of 42
ParaSail:  Parallel Specification and  Implementation Language S. Tucker Taft December 2011 An  AdaCore  Company
Outline of Presentation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Why Design A New Language for High-Integrity Systems? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Why a new language?  Computers have stopped getting faster Courtesy IEEE Computer, January 2011, page 33.
Building on Existing Languages ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Simplify, Unify, Parallelize, Formalize ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Simplify/Unify Modules and Types ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ParaSail approach for Modules/Types ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example: N-Queens Interface interface  N_Queens <N : Univ_Integer := 8>  is // Place N queens on an NxN checkerboard so that none of them can // &quot;take&quot; each other.  Return vector of solutions, each solution being // an array of columns indexed by row indicating placement of queens. type  Chess_Unit  is new  Integer<-N*2 .. N*2>; type  Row is Chess_Unit  {Row  in  1..N}; type  Column  is  Chess_Unit  {Column in 1..N}; type  Solution  is  Array< optional  Column, Indexed_By => Row>; func  Place_Queens() -> Vector<Solution> { for all  S  of  Place_Queens =>  for all  C  of  S => C  not null }; end interface  N_Queens;
Other ParaSail Module/Type  Features ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Simplify/Unify Arrays/Containers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ParaSail Approach for Containers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Containers Instead of Pointers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Why and How to Parallelize? ,[object Object],[object Object],[object Object],[object Object],[object Object]
Parallelism in ParaSail ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Expression and Statement Parallelism ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
More Examples of ParaSail Parallelism for  X => Root  then  X.Left || X.Right  while  X  not   null   concurrent   loop Process(X.Data);  // Process called on each node in parallel end   loop ; concurrent   interface  Box<Element  is  Assignable<>>  is func  Create() -> Box;  // Creates an empty box func  Put( locked   var  B : Box; E : Element); func  Get( queued   var  B : Box) -> Element;  // May wait func  Get_Now( locked  B : Box) ->  optional  Element; end   interface  Box; type  Item_Box  is  Box<Item>; var  My_Box : Item_Box := Create();
Synchronizing ParaSail Parallelism concurrent   class  Box <Element  is  Assignable<>>  is var  Content :  optional  Element;  // starts out null exports func  Create() -> Box  is   // Creates an empty box return  (Content =>  null ); end func  Create; func  Put( locked   var  B :   Box; E : Element)  is B.Content := E; end func  Put; func  Get( queued   var  B :   Box) -> Element  is   // May wait queued until  B.Content  not null   then const  Result := B.Content; B.Content :=  null ; return  Result; end func  Get; func  Get_Now( locked  B : Box) ->  optional  Element  is return  B.Content; end func  Get_Now; end   class  Box;
ParaSail Virtual Machine ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Why and How to Formalize? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Annotations in ParaSail ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Examples of ParaSail Annotations interface  Stack <Component  is  Assignable<>; Size_Type  is  Integer<>>  is func  Max_Stack_Size(S : Stack) -> Size_Type  {Max_Stack_Size > 0}; func  Count(S : Stack) -> Size_Type  {Count <= Max_Stack_Size(S)}; func  Create(Max : Size_Type {Max > 0}) -> Stack  {Max_Stack_Size(Create) == Max; Count(Create) == 0}; func  Is_Empty(S : Stack) -> Boolean {Is_Empty == (Count(S) == 0)}; func  Is_Full(S : Stack) -> Boolean {Is_Full == (Count(S) == Max_Stack_Size(S))}; func  Push( var  S : Stack { not  Is_Full(S)}; X : Component) {Count(S') == Count(S) + 1}; func  Top( ref  S : Stack  { not  Is_Empty(S)} ) ->  ref  Component; func  Pop( var  S :   Stack  { not  Is_Empty(S)} )  {Count(S') == Count(S) - 1}; end   interface  Stack;
More on Stack Annotations class  Stack <Component  is  Assignable<>; Size_Type  is  Integer<>>  is const  Max_Len : Size_Type; var  Cur_Len : Size_Type  {Cur_Len in 0..Max_Len}; type  Index_Type  is  Size_Type  {Index_Type in 1..Max_Len}; var  Data : Array< optional  Component, Indexed_By => Index_Type>;  exports {for all I in 1..Cur_Len => Data[I] not null}  // invariant for Top() ... func  Count(S : Stack) -> Size_Type {Count <= Max_Stack_Size(S)}  is return  S.Cur_Len; end func  Count;  func  Create(Max : Size_Type {Max > 0}) -> Stack {Max_Stack_Size(Create) == Max; Count(Create) == 0}  is return  (Max_Len => Max, Cur_Len => 0, Data => [.. =>  null ]); end func  Create; func  Push( var  S : Stack { not  Is_Full(S)}; X : Component) {Count(S') == Count(S) + 1}  is S.Cur_Len += 1;  // requires not Is_Full(S) precondition S.Data[S.Cur_Len] := X;  // preserves invariant (see above) end func  Push; func  Top( ref  S : Stack  { not  Is_Empty(S)} ) ->  ref  Component  is return  S.Data[S.Cur_Len]; // requires invariant (above) and not Is_Empty end func  Top;  end   class  Stack;
More Annotation Examples type  Age  is   new  Integer<0 .. 200>;  // a distinct integer type type  Youth  is  Age  {Youth <= 20};  // a sub-range type type  Senior  is  Age  {Senior >= 50};  // another sub-range type ---------------------------------- func  GCD(X, Y : Integer  {X > 0; Y > 0} ) -> Integer  {GCD > 0; GCD <= X; GCD <= Y;  X  mod  GCD == 0; Y  mod  GCD == 0}   is var  Result := X;  {Result > 0; X  mod  Result == 0} var  Next := Y  mod  X;  {Next <= Y; Y - Next  mod  Result == 0} while  Next != 0  loop {Next > 0; Next < Result; Result <= X} const  Old_Result := Result; Result := Next;  {Result < Old_Result} Next := Old_Result  mod  Result;  {Result > 0; Result <= Y; Old_Result - Next  mod  Result == 0} end   loop ; return  Result; end   func  GCD;
More on ParaSail Annotations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],block Monitor(Resource);  exit block with  Result =>  null; ||  Do_Work(Resource, Data);  exit block with  Result => Data;  end block;
More Parasail Examples
Walk Parse Tree in Parallel type  Node_Kind  is  Enum < [#leaf, #unary, #binary] >; ... for  X => Root  while  X  not null loop case  X.Kind  of [#leaf] => Process_Leaf(X); [#unary] => Process_Unary(X.Data) || continue loop with  X => X.Operand; [#binary] =>  Process_Binary(X.Data) || continue loop with  X => X.Left || continue loop with  X => X.Right; end case ; end loop ;
Map-Reduce in ParaSail ,[object Object],[object Object],[object Object],[object Object],[object Object]
Map-Reduce code func  Map_Reduce ( func  Map(Input  is  Any<>)    (Output  is  Any<>); func  Reduce(Left, Right : Output)    Output; Inputs : Vector<Input>)  {Length(Inputs) > 0}     Output  is // Handle singleton directly, recurse for longer inputs if  Length(Inputs) == 1  then return  Map(Inputs[1]); else // Split and recurse const  Half_Length := Length(Inputs)/2; return  Reduce (Map_Reduce(Map, Reduce, Inputs[1..Half_Length]), Map_Reduce(Map, Reduce, Inputs[Half_Length <.. Length(Inputs)])); end   if ; end   func  Map_Reduce; func  Test()  is  // Test Map_Reduce function -- compute sum of squares Print_Int(Map_Reduce (Map =>  lambda (X : Integer)    Integer  is  (X**2), Reduce => “+”, Inputs => [1, 2, 3, 4, 5, 6])); end   func  Test;
Real-Time Programming: Queued locking used for Delay abstract concurrent   interface  Clock <Time_Type  is  Ordered<>>  is func  Now(C : Clock) -> Time_Type; func  Delay_Until( queued  C : Clock; Wakeup : Time_Type) {Now(C’) >= Wakeup};  // queued until Now(C) >= Wakeup end   interface  Clock; concurrent   interface  Real_Time_Clock<...>  extends  Clock<...>  is func  Create(...) -> Real_Time_Clock; ... end interface  Real_Time_Clock; var  My_Clock : Real_Time_Clock <...> := Create(...); const  Too_Late := Now(My_Clock) + Max_Wait; block Delay_Until(My_Clock, Wakeup => Too_Late);  exit block with  (Result =>  null );  || const  Data := Get(My_Box);  Process(Data);  exit block with  (Result => Data); end   block ;
Parallel N-Queens Interface interface  N_Queens <N : Univ_Integer := 8> is // Place N queens on an NxN checkerboard so that none of them can // &quot;take&quot; each other.  Return vector of solutions, each solution being // an array of columns indexed by row indicating placement of queens. type  Chess_Unit  is new  Integer<-N*2 .. N*2>; type  Row is Chess_Unit  {Row  in  1..N}; type  Column  is  Chess_Unit  {Column in 1..N}; type  Solution  is  Array< optional  Column, Indexed_By => Row>; func  Place_Queens() -> Vector<Solution> { for all  S  of  Place_Queens =>  for all  Col  of  S => Col  not null }; // Produce a vector of solutions, with the requirement // that for each solution, there are non-null column numbers // specified for each row of the checkerboard. end interface  N_Queens;
Parallel N-Queens Class (cont’d) class  N_Queens  is interface  Solution_State<>  is ...  // local nested module class  Solution_State  is type  Sum  is  Set<2..2*N>; // Diagonals where R+C = K type  Diff  is  Set<(1-N) .. (N-1)>; // Diagonals where R-C = K ... end class  Solution_State; exports func  Place_Queens() -> Vector<Solution> { for all  S  of  Place_Queens =>  for all  Col  of  S => Col  not null } is var  Solutions :  concurrent  Vector<Solution> := []; *Outer_Loop* for  State : Solution_State := Initial_State()  loop // Iterate over the columns   ...   // All done, remember trial result with last queen placed Solutions |= Final_Result(State, R);  ... end loop  Outer_Loop; return  Solutions; end func  Place_Queens; end class  N_Queens;
Parallel N-Queens Class (cont’d) func  Place_Queens() -> Vector<Solution>  is var  Solutions :  concurrent  Vector<Solution> := []; *Outer_Loop* for  State : Solution_State := Initial_State()  loop   // over the columns for  R  in  Row  concurrent loop   // over the rows (in parallel) if  Is_Acceptable(State, R)  then // Found a Row/Column combination that is not on any “busy” diagonal if  Current_Column(State) < N  then   // Keep going since haven't reached Nth column. continue loop  Outer_Loop  with  Next_State(State, R); else   // All done, remember trial result with last queen placed Solutions |= Final_Result(State, R);  end if ; end if ; end loop ; end loop  Outer_Loop; return  Solutions; end func  Place_Queens;
Assessing Parasail
Summarizing ParaSail Model ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
User-defined Indexing, Literals, etc. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What makes ParaSail Interesting? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How does ParaSail Compare to ... ,[object Object],[object Object],[object Object],[object Object]
Some of the Open Issues in ParaSail ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Ultimate Test of Type Model: Physical Units Example interface  Float_With_Units <Base  is  Float<>; Name : Univ_String; Short_Hand : Univ_String; Unit_Dimensions : Array <Element_Type => Univ_Real,  Index_Type => Dimension_Enum> := [ ..  => 0.0]; Scale : Univ_Real>  is op  &quot;from_univ&quot;(Value : Univ_Real)  {Value  in  Base::First*Scale .. Base::Last*Scale}  -> Float_With_Units; op  &quot;to_univ&quot;(Value : Float_With_Units) -> Result : Univ_Real  {Result in Base::First*Scale .. Base::Last*Scale}; op  &quot;+&quot;(Left, Right : Float_With_Units) -> Result : Float_With_Units  {[[Result]] == [[Left]] + [[Right]]}; op  &quot;=?&quot;(Left, Right : Float_With_Units) -> Ordering; op  &quot;*&quot;(Left : Float_With_Units; Right : Right_Type  is  Float_With_Units<>) -> Result : Result_Type  is  Float_With_Units<Unit_Dimensions =>  Unit_Dimensions + Right_Type::Unit_Dimensions> {[[Result]] == [[Left]] * [[Right]]}; op  &quot;/&quot;(Left : Left_Type  is  ... end   interface  Float_With_Units; type  Meters  is  Float_With_Units<Name => “centimeters”, Short_Hand => “cm”, Unit_Dimensions => [#m => 1.0, #k => 0.0, #s => 0.0], Scale => 0.01>;
Conclusions and Ongoing Work ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],24 Muzzey Street Lexington, MA 02421 An  AdaCore  Company

More Related Content

What's hot

Why we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingWhy we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingMario Fusco
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scalaStratio
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programmingRiccardo Cardin
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8LivePerson
 
Java best practices
Java best practicesJava best practices
Java best practicesRay Toal
 
Lambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzLambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzJAX London
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming CourseDennis Chang
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency ConstructsTed Leung
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programmingDhaval Dalal
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Rasan Samarasinghe
 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNico Ludwig
 
Method Handles in Java
Method Handles in JavaMethod Handles in Java
Method Handles in Javahendersk
 
What's New In Python 2.5
What's New In Python 2.5What's New In Python 2.5
What's New In Python 2.5Richard Jones
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.pptTareq Hasan
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#sudipv
 
What's New In Python 2.4
What's New In Python 2.4What's New In Python 2.4
What's New In Python 2.4Richard Jones
 

What's hot (20)

Why we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingWhy we cannot ignore Functional Programming
Why we cannot ignore Functional Programming
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scala
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Java best practices
Java best practicesJava best practices
Java best practices
 
Lambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian GoetzLambda: A Peek Under The Hood - Brian Goetz
Lambda: A Peek Under The Hood - Brian Goetz
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programming
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
 
Of Lambdas and LINQ
Of Lambdas and LINQOf Lambdas and LINQ
Of Lambdas and LINQ
 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_ii
 
Method Handles in Java
Method Handles in JavaMethod Handles in Java
Method Handles in Java
 
ALGOL ailesi programlama dilleri
ALGOL ailesi programlama dilleriALGOL ailesi programlama dilleri
ALGOL ailesi programlama dilleri
 
Swift, swiftly
Swift, swiftlySwift, swiftly
Swift, swiftly
 
What's New In Python 2.5
What's New In Python 2.5What's New In Python 2.5
What's New In Python 2.5
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.ppt
 
Learn Java Part 2
Learn Java Part 2Learn Java Part 2
Learn Java Part 2
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#
 
What's New In Python 2.4
What's New In Python 2.4What's New In Python 2.4
What's New In Python 2.4
 

Viewers also liked

Ada 202x A broad overview of relevant news
Ada 202x A broad overview of relevant newsAda 202x A broad overview of relevant news
Ada 202x A broad overview of relevant newsAdaCore
 
Bounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise EnvironmentBounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise EnvironmentAdaCore
 
Multi-Core (MC) Processor Qualification for Safety Critical Systems
Multi-Core (MC) Processor Qualification for Safety Critical SystemsMulti-Core (MC) Processor Qualification for Safety Critical Systems
Multi-Core (MC) Processor Qualification for Safety Critical SystemsAdaCore
 
The Application of Formal Methods to Railway Signalling Software
The Application of Formal Methods to Railway Signalling SoftwareThe Application of Formal Methods to Railway Signalling Software
The Application of Formal Methods to Railway Signalling SoftwareAdaCore
 
Multiprocessor architecture and programming
Multiprocessor architecture and programmingMultiprocessor architecture and programming
Multiprocessor architecture and programmingRaul Goycoolea Seoane
 

Viewers also liked (6)

Paragliding
ParaglidingParagliding
Paragliding
 
Ada 202x A broad overview of relevant news
Ada 202x A broad overview of relevant newsAda 202x A broad overview of relevant news
Ada 202x A broad overview of relevant news
 
Bounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise EnvironmentBounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise Environment
 
Multi-Core (MC) Processor Qualification for Safety Critical Systems
Multi-Core (MC) Processor Qualification for Safety Critical SystemsMulti-Core (MC) Processor Qualification for Safety Critical Systems
Multi-Core (MC) Processor Qualification for Safety Critical Systems
 
The Application of Formal Methods to Railway Signalling Software
The Application of Formal Methods to Railway Signalling SoftwareThe Application of Formal Methods to Railway Signalling Software
The Application of Formal Methods to Railway Signalling Software
 
Multiprocessor architecture and programming
Multiprocessor architecture and programmingMultiprocessor architecture and programming
Multiprocessor architecture and programming
 

Similar to ParaSail (20)

Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinal
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinal
 
Start with swift
Start with swiftStart with swift
Start with swift
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
Andy On Closures
Andy On ClosuresAndy On Closures
Andy On Closures
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
 
Scala presentationjune112011
Scala presentationjune112011Scala presentationjune112011
Scala presentationjune112011
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 

More from AdaCore

RCA OCORA: Safe Computing Platform using open standards
RCA OCORA: Safe Computing Platform using open standardsRCA OCORA: Safe Computing Platform using open standards
RCA OCORA: Safe Computing Platform using open standardsAdaCore
 
Have we a Human Ecosystem?
Have we a Human Ecosystem?Have we a Human Ecosystem?
Have we a Human Ecosystem?AdaCore
 
Rust and the coming age of high integrity languages
Rust and the coming age of high integrity languagesRust and the coming age of high integrity languages
Rust and the coming age of high integrity languagesAdaCore
 
SPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic librarySPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic libraryAdaCore
 
Developing Future High Integrity Processing Solutions
Developing Future High Integrity Processing SolutionsDeveloping Future High Integrity Processing Solutions
Developing Future High Integrity Processing SolutionsAdaCore
 
Taming event-driven software via formal verification
Taming event-driven software via formal verificationTaming event-driven software via formal verification
Taming event-driven software via formal verificationAdaCore
 
Pushing the Boundary of Mostly Automatic Program Proof
Pushing the Boundary of Mostly Automatic Program ProofPushing the Boundary of Mostly Automatic Program Proof
Pushing the Boundary of Mostly Automatic Program ProofAdaCore
 
RCA OCORA: Safe Computing Platform using open standards
RCA OCORA: Safe Computing Platform using open standardsRCA OCORA: Safe Computing Platform using open standards
RCA OCORA: Safe Computing Platform using open standardsAdaCore
 
Product Lines and Ecosystems: from customization to configuration
Product Lines and Ecosystems: from customization to configurationProduct Lines and Ecosystems: from customization to configuration
Product Lines and Ecosystems: from customization to configurationAdaCore
 
Securing the Future of Safety and Security of Embedded Software
Securing the Future of Safety and Security of Embedded SoftwareSecuring the Future of Safety and Security of Embedded Software
Securing the Future of Safety and Security of Embedded SoftwareAdaCore
 
Spark / Ada for Safe and Secure Firmware Development
Spark / Ada for Safe and Secure Firmware DevelopmentSpark / Ada for Safe and Secure Firmware Development
Spark / Ada for Safe and Secure Firmware DevelopmentAdaCore
 
Introducing the HICLASS Research Programme - Enabling Development of Complex ...
Introducing the HICLASS Research Programme - Enabling Development of Complex ...Introducing the HICLASS Research Programme - Enabling Development of Complex ...
Introducing the HICLASS Research Programme - Enabling Development of Complex ...AdaCore
 
The Future of Aerospace – More Software Please!
The Future of Aerospace – More Software Please!The Future of Aerospace – More Software Please!
The Future of Aerospace – More Software Please!AdaCore
 
Adaptive AUTOSAR - The New AUTOSAR Architecture
Adaptive AUTOSAR - The New AUTOSAR ArchitectureAdaptive AUTOSAR - The New AUTOSAR Architecture
Adaptive AUTOSAR - The New AUTOSAR ArchitectureAdaCore
 
Using Tiers of Assurance Evidence to Reduce the Tears! Adopting the “Wheel of...
Using Tiers of Assurance Evidence to Reduce the Tears! Adopting the “Wheel of...Using Tiers of Assurance Evidence to Reduce the Tears! Adopting the “Wheel of...
Using Tiers of Assurance Evidence to Reduce the Tears! Adopting the “Wheel of...AdaCore
 
Software Engineering for Robotics - The RoboStar Technology
Software Engineering for Robotics - The RoboStar TechnologySoftware Engineering for Robotics - The RoboStar Technology
Software Engineering for Robotics - The RoboStar TechnologyAdaCore
 
MISRA C in an ISO 26262 context
MISRA C in an ISO 26262 contextMISRA C in an ISO 26262 context
MISRA C in an ISO 26262 contextAdaCore
 
Application of theorem proving for safety-critical vehicle software
Application of theorem proving for safety-critical vehicle softwareApplication of theorem proving for safety-critical vehicle software
Application of theorem proving for safety-critical vehicle softwareAdaCore
 
Verification and Validation of Robotic Assistants
Verification and Validation of Robotic AssistantsVerification and Validation of Robotic Assistants
Verification and Validation of Robotic AssistantsAdaCore
 
An Alternative Approach to DO-178B
An Alternative Approach to DO-178BAn Alternative Approach to DO-178B
An Alternative Approach to DO-178BAdaCore
 

More from AdaCore (20)

RCA OCORA: Safe Computing Platform using open standards
RCA OCORA: Safe Computing Platform using open standardsRCA OCORA: Safe Computing Platform using open standards
RCA OCORA: Safe Computing Platform using open standards
 
Have we a Human Ecosystem?
Have we a Human Ecosystem?Have we a Human Ecosystem?
Have we a Human Ecosystem?
 
Rust and the coming age of high integrity languages
Rust and the coming age of high integrity languagesRust and the coming age of high integrity languages
Rust and the coming age of high integrity languages
 
SPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic librarySPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic library
 
Developing Future High Integrity Processing Solutions
Developing Future High Integrity Processing SolutionsDeveloping Future High Integrity Processing Solutions
Developing Future High Integrity Processing Solutions
 
Taming event-driven software via formal verification
Taming event-driven software via formal verificationTaming event-driven software via formal verification
Taming event-driven software via formal verification
 
Pushing the Boundary of Mostly Automatic Program Proof
Pushing the Boundary of Mostly Automatic Program ProofPushing the Boundary of Mostly Automatic Program Proof
Pushing the Boundary of Mostly Automatic Program Proof
 
RCA OCORA: Safe Computing Platform using open standards
RCA OCORA: Safe Computing Platform using open standardsRCA OCORA: Safe Computing Platform using open standards
RCA OCORA: Safe Computing Platform using open standards
 
Product Lines and Ecosystems: from customization to configuration
Product Lines and Ecosystems: from customization to configurationProduct Lines and Ecosystems: from customization to configuration
Product Lines and Ecosystems: from customization to configuration
 
Securing the Future of Safety and Security of Embedded Software
Securing the Future of Safety and Security of Embedded SoftwareSecuring the Future of Safety and Security of Embedded Software
Securing the Future of Safety and Security of Embedded Software
 
Spark / Ada for Safe and Secure Firmware Development
Spark / Ada for Safe and Secure Firmware DevelopmentSpark / Ada for Safe and Secure Firmware Development
Spark / Ada for Safe and Secure Firmware Development
 
Introducing the HICLASS Research Programme - Enabling Development of Complex ...
Introducing the HICLASS Research Programme - Enabling Development of Complex ...Introducing the HICLASS Research Programme - Enabling Development of Complex ...
Introducing the HICLASS Research Programme - Enabling Development of Complex ...
 
The Future of Aerospace – More Software Please!
The Future of Aerospace – More Software Please!The Future of Aerospace – More Software Please!
The Future of Aerospace – More Software Please!
 
Adaptive AUTOSAR - The New AUTOSAR Architecture
Adaptive AUTOSAR - The New AUTOSAR ArchitectureAdaptive AUTOSAR - The New AUTOSAR Architecture
Adaptive AUTOSAR - The New AUTOSAR Architecture
 
Using Tiers of Assurance Evidence to Reduce the Tears! Adopting the “Wheel of...
Using Tiers of Assurance Evidence to Reduce the Tears! Adopting the “Wheel of...Using Tiers of Assurance Evidence to Reduce the Tears! Adopting the “Wheel of...
Using Tiers of Assurance Evidence to Reduce the Tears! Adopting the “Wheel of...
 
Software Engineering for Robotics - The RoboStar Technology
Software Engineering for Robotics - The RoboStar TechnologySoftware Engineering for Robotics - The RoboStar Technology
Software Engineering for Robotics - The RoboStar Technology
 
MISRA C in an ISO 26262 context
MISRA C in an ISO 26262 contextMISRA C in an ISO 26262 context
MISRA C in an ISO 26262 context
 
Application of theorem proving for safety-critical vehicle software
Application of theorem proving for safety-critical vehicle softwareApplication of theorem proving for safety-critical vehicle software
Application of theorem proving for safety-critical vehicle software
 
Verification and Validation of Robotic Assistants
Verification and Validation of Robotic AssistantsVerification and Validation of Robotic Assistants
Verification and Validation of Robotic Assistants
 
An Alternative Approach to DO-178B
An Alternative Approach to DO-178BAn Alternative Approach to DO-178B
An Alternative Approach to DO-178B
 

Recently uploaded

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Recently uploaded (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 

ParaSail

  • 1. ParaSail: Parallel Specification and Implementation Language S. Tucker Taft December 2011 An AdaCore Company
  • 2.
  • 3.
  • 4. Why a new language? Computers have stopped getting faster Courtesy IEEE Computer, January 2011, page 33.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. Example: N-Queens Interface interface N_Queens <N : Univ_Integer := 8> is // Place N queens on an NxN checkerboard so that none of them can // &quot;take&quot; each other. Return vector of solutions, each solution being // an array of columns indexed by row indicating placement of queens. type Chess_Unit is new Integer<-N*2 .. N*2>; type Row is Chess_Unit {Row in 1..N}; type Column is Chess_Unit {Column in 1..N}; type Solution is Array< optional Column, Indexed_By => Row>; func Place_Queens() -> Vector<Solution> { for all S of Place_Queens => for all C of S => C not null }; end interface N_Queens;
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17. More Examples of ParaSail Parallelism for X => Root then X.Left || X.Right while X not null concurrent loop Process(X.Data); // Process called on each node in parallel end loop ; concurrent interface Box<Element is Assignable<>> is func Create() -> Box; // Creates an empty box func Put( locked var B : Box; E : Element); func Get( queued var B : Box) -> Element; // May wait func Get_Now( locked B : Box) -> optional Element; end interface Box; type Item_Box is Box<Item>; var My_Box : Item_Box := Create();
  • 18. Synchronizing ParaSail Parallelism concurrent class Box <Element is Assignable<>> is var Content : optional Element; // starts out null exports func Create() -> Box is // Creates an empty box return (Content => null ); end func Create; func Put( locked var B : Box; E : Element) is B.Content := E; end func Put; func Get( queued var B : Box) -> Element is // May wait queued until B.Content not null then const Result := B.Content; B.Content := null ; return Result; end func Get; func Get_Now( locked B : Box) -> optional Element is return B.Content; end func Get_Now; end class Box;
  • 19.
  • 20.
  • 21.
  • 22. Examples of ParaSail Annotations interface Stack <Component is Assignable<>; Size_Type is Integer<>> is func Max_Stack_Size(S : Stack) -> Size_Type {Max_Stack_Size > 0}; func Count(S : Stack) -> Size_Type {Count <= Max_Stack_Size(S)}; func Create(Max : Size_Type {Max > 0}) -> Stack {Max_Stack_Size(Create) == Max; Count(Create) == 0}; func Is_Empty(S : Stack) -> Boolean {Is_Empty == (Count(S) == 0)}; func Is_Full(S : Stack) -> Boolean {Is_Full == (Count(S) == Max_Stack_Size(S))}; func Push( var S : Stack { not Is_Full(S)}; X : Component) {Count(S') == Count(S) + 1}; func Top( ref S : Stack { not Is_Empty(S)} ) -> ref Component; func Pop( var S : Stack { not Is_Empty(S)} ) {Count(S') == Count(S) - 1}; end interface Stack;
  • 23. More on Stack Annotations class Stack <Component is Assignable<>; Size_Type is Integer<>> is const Max_Len : Size_Type; var Cur_Len : Size_Type {Cur_Len in 0..Max_Len}; type Index_Type is Size_Type {Index_Type in 1..Max_Len}; var Data : Array< optional Component, Indexed_By => Index_Type>; exports {for all I in 1..Cur_Len => Data[I] not null} // invariant for Top() ... func Count(S : Stack) -> Size_Type {Count <= Max_Stack_Size(S)} is return S.Cur_Len; end func Count; func Create(Max : Size_Type {Max > 0}) -> Stack {Max_Stack_Size(Create) == Max; Count(Create) == 0} is return (Max_Len => Max, Cur_Len => 0, Data => [.. => null ]); end func Create; func Push( var S : Stack { not Is_Full(S)}; X : Component) {Count(S') == Count(S) + 1} is S.Cur_Len += 1; // requires not Is_Full(S) precondition S.Data[S.Cur_Len] := X; // preserves invariant (see above) end func Push; func Top( ref S : Stack { not Is_Empty(S)} ) -> ref Component is return S.Data[S.Cur_Len]; // requires invariant (above) and not Is_Empty end func Top; end class Stack;
  • 24. More Annotation Examples type Age is new Integer<0 .. 200>; // a distinct integer type type Youth is Age {Youth <= 20}; // a sub-range type type Senior is Age {Senior >= 50}; // another sub-range type ---------------------------------- func GCD(X, Y : Integer {X > 0; Y > 0} ) -> Integer {GCD > 0; GCD <= X; GCD <= Y; X mod GCD == 0; Y mod GCD == 0} is var Result := X; {Result > 0; X mod Result == 0} var Next := Y mod X; {Next <= Y; Y - Next mod Result == 0} while Next != 0 loop {Next > 0; Next < Result; Result <= X} const Old_Result := Result; Result := Next; {Result < Old_Result} Next := Old_Result mod Result; {Result > 0; Result <= Y; Old_Result - Next mod Result == 0} end loop ; return Result; end func GCD;
  • 25.
  • 27. Walk Parse Tree in Parallel type Node_Kind is Enum < [#leaf, #unary, #binary] >; ... for X => Root while X not null loop case X.Kind of [#leaf] => Process_Leaf(X); [#unary] => Process_Unary(X.Data) || continue loop with X => X.Operand; [#binary] => Process_Binary(X.Data) || continue loop with X => X.Left || continue loop with X => X.Right; end case ; end loop ;
  • 28.
  • 29. Map-Reduce code func Map_Reduce ( func Map(Input is Any<>)  (Output is Any<>); func Reduce(Left, Right : Output)  Output; Inputs : Vector<Input>) {Length(Inputs) > 0}  Output is // Handle singleton directly, recurse for longer inputs if Length(Inputs) == 1 then return Map(Inputs[1]); else // Split and recurse const Half_Length := Length(Inputs)/2; return Reduce (Map_Reduce(Map, Reduce, Inputs[1..Half_Length]), Map_Reduce(Map, Reduce, Inputs[Half_Length <.. Length(Inputs)])); end if ; end func Map_Reduce; func Test() is // Test Map_Reduce function -- compute sum of squares Print_Int(Map_Reduce (Map => lambda (X : Integer)  Integer is (X**2), Reduce => “+”, Inputs => [1, 2, 3, 4, 5, 6])); end func Test;
  • 30. Real-Time Programming: Queued locking used for Delay abstract concurrent interface Clock <Time_Type is Ordered<>> is func Now(C : Clock) -> Time_Type; func Delay_Until( queued C : Clock; Wakeup : Time_Type) {Now(C’) >= Wakeup}; // queued until Now(C) >= Wakeup end interface Clock; concurrent interface Real_Time_Clock<...> extends Clock<...> is func Create(...) -> Real_Time_Clock; ... end interface Real_Time_Clock; var My_Clock : Real_Time_Clock <...> := Create(...); const Too_Late := Now(My_Clock) + Max_Wait; block Delay_Until(My_Clock, Wakeup => Too_Late); exit block with (Result => null ); || const Data := Get(My_Box); Process(Data); exit block with (Result => Data); end block ;
  • 31. Parallel N-Queens Interface interface N_Queens <N : Univ_Integer := 8> is // Place N queens on an NxN checkerboard so that none of them can // &quot;take&quot; each other. Return vector of solutions, each solution being // an array of columns indexed by row indicating placement of queens. type Chess_Unit is new Integer<-N*2 .. N*2>; type Row is Chess_Unit {Row in 1..N}; type Column is Chess_Unit {Column in 1..N}; type Solution is Array< optional Column, Indexed_By => Row>; func Place_Queens() -> Vector<Solution> { for all S of Place_Queens => for all Col of S => Col not null }; // Produce a vector of solutions, with the requirement // that for each solution, there are non-null column numbers // specified for each row of the checkerboard. end interface N_Queens;
  • 32. Parallel N-Queens Class (cont’d) class N_Queens is interface Solution_State<> is ... // local nested module class Solution_State is type Sum is Set<2..2*N>; // Diagonals where R+C = K type Diff is Set<(1-N) .. (N-1)>; // Diagonals where R-C = K ... end class Solution_State; exports func Place_Queens() -> Vector<Solution> { for all S of Place_Queens => for all Col of S => Col not null } is var Solutions : concurrent Vector<Solution> := []; *Outer_Loop* for State : Solution_State := Initial_State() loop // Iterate over the columns ... // All done, remember trial result with last queen placed Solutions |= Final_Result(State, R); ... end loop Outer_Loop; return Solutions; end func Place_Queens; end class N_Queens;
  • 33. Parallel N-Queens Class (cont’d) func Place_Queens() -> Vector<Solution> is var Solutions : concurrent Vector<Solution> := []; *Outer_Loop* for State : Solution_State := Initial_State() loop // over the columns for R in Row concurrent loop // over the rows (in parallel) if Is_Acceptable(State, R) then // Found a Row/Column combination that is not on any “busy” diagonal if Current_Column(State) < N then // Keep going since haven't reached Nth column. continue loop Outer_Loop with Next_State(State, R); else // All done, remember trial result with last queen placed Solutions |= Final_Result(State, R); end if ; end if ; end loop ; end loop Outer_Loop; return Solutions; end func Place_Queens;
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40. Ultimate Test of Type Model: Physical Units Example interface Float_With_Units <Base is Float<>; Name : Univ_String; Short_Hand : Univ_String; Unit_Dimensions : Array <Element_Type => Univ_Real, Index_Type => Dimension_Enum> := [ .. => 0.0]; Scale : Univ_Real> is op &quot;from_univ&quot;(Value : Univ_Real) {Value in Base::First*Scale .. Base::Last*Scale} -> Float_With_Units; op &quot;to_univ&quot;(Value : Float_With_Units) -> Result : Univ_Real {Result in Base::First*Scale .. Base::Last*Scale}; op &quot;+&quot;(Left, Right : Float_With_Units) -> Result : Float_With_Units {[[Result]] == [[Left]] + [[Right]]}; op &quot;=?&quot;(Left, Right : Float_With_Units) -> Ordering; op &quot;*&quot;(Left : Float_With_Units; Right : Right_Type is Float_With_Units<>) -> Result : Result_Type is Float_With_Units<Unit_Dimensions => Unit_Dimensions + Right_Type::Unit_Dimensions> {[[Result]] == [[Left]] * [[Right]]}; op &quot;/&quot;(Left : Left_Type is ... end interface Float_With_Units; type Meters is Float_With_Units<Name => “centimeters”, Short_Hand => “cm”, Unit_Dimensions => [#m => 1.0, #k => 0.0, #s => 0.0], Scale => 0.01>;
  • 41.
  • 42.