C++11 CSP - WoTUG

Loading...

C++11 CSP Because we haven’t built enough CSP libraries

Dr Kevin Chalmers School of Computing Edinburgh Napier University Edinburgh [email protected]

Before we get started...

ˆ Yes you can pull it (although it needs more testing) ˆ http://github.com/kevin-chalmers/cpp11-csp

Outline 1 OK why did you do this? 2 OK, but why did you really do this? 3 But C++ is old hat! 4 How to use C++11 CSP 5 Some Examples 6 Patterns and Networking and Other Stuff 7 Summary

Outline 1 OK why did you do this? 2 OK, but why did you really do this? 3 But C++ is old hat! 4 How to use C++11 CSP 5 Some Examples 6 Patterns and Networking and Other Stuff 7 Summary

Little Trajectory - occam to networking

ˆ I started off working with JCSP way back in 2004 ˆ Undergraduate module in Design Patterns including parallel ˆ An iteration of material Jon had been running as occam for years ˆ My undergraduate project looked at code mobility in JCSP ˆ My PhD work looked at networking and networked mobility

Little Trajectory - networking to occam

ˆ One outcome of this work was a generalised protocol for

networked channel communications ˆ I developed a .NET version ˆ Connecting, via channels, JCSP and .NET CSP ˆ I then set off an occam journey, trying to implement the

networking stack ˆ And it was too hard ˆ The networking stack relied too heavily on object-orientation

ideas and some data sharing

Stepping Back - C and MPI ˆ So I took a step back and thought about redesigning in

another language ˆ C and C++ being the most likely ˆ Cross runtime potential with foreign function interface ˆ I’ll get back to this

ˆ As a sidetrack I started exploring MPI to compare against

what I had ˆ De facto standard for message passing in distributed parallel

ˆ I became interested in MPI as a potential comm layer, but

this requires a redesign of networking ˆ Too stream focused

ˆ So, I am really trying to create a framework which sits on top

of MPI ˆ And the simplest method was to move away from Java to C or

C++

An aside - C++CSP Already Exists!

ˆ Neil Brown did a lot of work on a C++ version of a CSP

library ˆ Also created C++CSP2 ˆ Also created C++CSP2 Networked ˆ So why not just use Neil’s work? ˆ Well, C++CSP2 is not very extensible ˆ Couldn’t implement the networked channel model I had easily ˆ Would have to strip down C++CSP2 to achieve what I wanted ˆ Also relied heavily on Boost and OS specific libraries

Outline 1 OK why did you do this? 2 OK, but why did you really do this? 3 But C++ is old hat! 4 How to use C++11 CSP 5 Some Examples 6 Patterns and Networking and Other Stuff 7 Summary

JCSP Code is Rotten!

ˆ Oh how much do I hate writing JCSP code! ˆ Actually, I hate writing Java code - JCSP does a good job of

hiding Javaisms—(Chalmers 2015)

ˆ I want to decide if I am passing by value or reference ˆ I want to decide how and when an object is destroyed ˆ I want to override operators ˆ I could go on...

I like the expressiveness of parallel computation in occam

ˆ I do - even though I’ve never been an occam programmer ˆ What I don’t like is the lack of libraries ˆ As a programmer I find libraries more important than the language ˆ I can work round the language with APIs ˆ I also find occam a little archaic ˆ But let’s not start an argument about it ˆ So I want the simplicity of occam, but with massive library

and platform support ˆ These two issues quite happily collided

Outline 1 OK why did you do this? 2 OK, but why did you really do this? 3 But C++ is old hat! 4 How to use C++11 CSP 5 Some Examples 6 Patterns and Networking and Other Stuff 7 Summary

C++11 - Not your grandfather’s C++

ˆ C++ is an object-oriented language ˆ No - but you can write object-oriented code with C++ ˆ A lot of Java programmers (including me) write bad C++ code ˆ C++ is too complex ˆ Depends on your approach - you can write complex code with C++ ˆ I like to tell students that C++ is not a forgiving language ˆ C++ relies on pointers ˆ No - most C programmers wrote a lot of bad C++ code ˆ What C++ is is up for debate ˆ It is multi-paradigm. If actor models take off you can guarantee that C++ will get send and receive or similar

New C++ Features ˆ OK, there are a lot, so I’ll summarise the important bits

Smart pointers Automatic release of resources - no need for new and delete Lambda Expressions You can do pretty much standard functional language stuff - it just gets pretty ugly Move semantics You can now move resources as well as copy and reference ˆ Yes, this is just occam-π mobile data types

Initializer lists Create collections using braces to denote the members Variadic templates Compiler does more work for the type Concurrency FINALLY! We get ˆ ˆ ˆ ˆ

Thread Mutex Future etc.

Modern C++ Design

ˆ OK, last slide before getting onto some code ˆ Modern C++ design encourages the following approaches

Avoid pointers Most memory should have a handler object that looks after the resource PIMPL Private implementation objects surrounded by a handler RAII Resource lifetime is linked to the lifetime of its owner Generic programming Templates to create reusable code

Outline 1 OK why did you do this? 2 OK, but why did you really do this? 3 But C++ is old hat! 4 How to use C++11 CSP 5 Some Examples 6 Patterns and Networking and Other Stuff 7 Summary

Channels

Creating and Using Channels // Channels are typed one2one_chan < int > c ; // Operator overloads for read and write auto x = c () ; c(x); // Also overloads to automatically convert to chan_in , chan_out , etc .

Processes

Processes are Just Functions // Lambda expression auto send = [&]() { c (5) ; }; auto recv = [&]() { cout << c () << endl ; }; // Can also bind functions with values // void sender ( chan_out < int > c ) // void receiver ( chan_in < int > c ) fork f1 ( make_proc ( sender , c ) ) ; fork f2 ( make_proc ( reciever , c ) ) ; f1 () ; f2 () ;

Parallel

par uses Initializer Lists // Parallel now looks like a control block par { prefix (0 , a , b ) , delta (b , {c , d }) , succ (c , a ) , printer ( " " , " " , d ) }() ;

ˆ I’d like to do something similar with alt - have an idea for

that

Outline 1 OK why did you do this? 2 OK, but why did you really do this? 3 But C++ is old hat! 4 How to use C++11 CSP 5 Some Examples 6 Patterns and Networking and Other Stuff 7 Summary

Outline 1 OK why did you do this? 2 OK, but why did you really do this? 3 But C++ is old hat! 4 How to use C++11 CSP 5 Some Examples 6 Patterns and Networking and Other Stuff 7 Summary

There is still a bit I’d like to do...

ˆ Building the pattern functions for C++11 CSP got me

interested in parallel patterns ˆ I’ll talk about this more tomorrow ˆ I’m almost there with a new networking stack ˆ Far more versatile and extensible ˆ Will require only little bits of code to enable new comm layers

ˆ I’d like automatic fork management (i.e. you fork a process

you have to wait for it to complete) ˆ I’d like other syntactic sugar approaches built in (e.g. alt)

Outline 1 OK why did you do this? 2 OK, but why did you really do this? 3 But C++ is old hat! 4 How to use C++11 CSP 5 Some Examples 6 Patterns and Networking and Other Stuff 7 Summary

Summary

ˆ This is very much a pet project to let me explore ideas ˆ I’m not aiming for performance, but simplicity of code ˆ My main aim is to build a new MPI supported network stack

for channel processes ˆ And hopefully stick that into Go, Rust, etc. ˆ So, happy enough to share code, but don’t expect support at

the moment

Questions?

Loading...

C++11 CSP - WoTUG

C++11 CSP Because we haven’t built enough CSP libraries Dr Kevin Chalmers School of Computing Edinburgh Napier University Edinburgh [email protected]

3MB Sizes 0 Downloads 0 Views

Recommend Documents

Technical specification - CSP Architectural
load factors in accordance with AS1170.0 – 2002 and. AS 1170.1 – 2002. 8. The tables assume that the tops of the ...

Installation Instructions - CSP Architectural
IMPORTANT NOTES. 1. Failure to install, finish or maintain this product in accordance with applicable building codes, re

Study Protocol CSP #556 - ClinicalTrials.gov
Items 18 - 23 - DSM-IV criteria for Major Depression and all will have failed at least two ... trial involved 301 medica

HardiePanel Comp Flooring Covers:HardiPanel - CSP Architectural
HARDIEPANEL COMPRESSED FLOORING INSTALLATION MANUAL JANUARY 2012 5. 3 DESIGN. GENERAL. The Building Code of Australia (B

Idea CSP Detail S. No CSP Name Address City State PIN - Axis Bank
140 RAJESH KUMAR SINGH. S/O SOMARI SINGH VILL JAMUNAHAANCHAL PANCHADEVARI. DT GOPAL. GOPALGANJ. BIHAR. 841425. 919708341

2017 Career Sea Pay (CSP) | Military Benefits
Monthly Career Sea Pay charts for Coast Guard, Navy, Marine Corps, Air Force and Army service members at a monthly rate

CSP Syllabus Jan. 2016 - Code.org
likely to put all students on a level playing field for the first few weeks of class. Read more .... familiarize yoursel

Three New Pringles Flavors | CSP Daily News
Nov 20, 2012 - "With more than 80 varieties of Pringles crisps available worldwide, we are constantly looking for innova

(FHWA) Cybersecurity Program (CSP) Handbook - Federal Highway
The FHWA CSP Handbook is comprised of policies, procedures, and guidance for ensuring the ... and documentation of curre

3i : Islam, Iman & Ihsan (C11) OP - Moncah.my
Ihsan mampu menjadi penentu kepada kejayaan Iman dan Islam dalam konsep 3i apabila dilaksanakan oleh individu. Ini keran