SystemCoDesigner: System Programming Tutorial

Size: px
Start display at page:

Download "SystemCoDesigner: System Programming Tutorial"

Transcription

1 SystemCoDesigner: System Programming Tutorial Martin Streubühr Falk Christian Zebelein Hardware/Software Co-Design Department of Computer Science University of Erlangen-Nuremberg Germany Version 1.2 Christian Haubelt Joachim

2 Outline Introduction Programming Examples Advanced Data Flow Modeling Remarks Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 2

3 Introduction

4 Introduction SysteMoC Concepts SystemCoDesigner uses SysteMoC as input language SysteMoC is implemented on top of SystemC... uses actor-oriented design for modeling... supports data flow models of computation (MoC) Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 4

5 Introduction SysteMoC Concepts the SysteMoC library defines channels for data flow... syntax for modeling actor communication behavior as FSMs SysteMoC SysteMoC Elementary channels separating functionality and communication C++ syntax for specifying actor communication behaviour as FSMs Scheduler for (dynamic) dataflow MoC domain Elementary Channels Signal, timer, mutex, semaphore, FIFO, etc... SystemC Core Languages Modules Ports Processes Events Interfaces Channels Data Types 4 valued logic types 4 valued logic vectors Bits and bit vectors Arbitrary precision integers Fixed point numbers C++ user defined types Event driven Simulation Kernel Events, Processes, etc... C++ C++ Language Standard Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 5

6 Introduction SysteMoC Concepts produce() approximate() o 1 # 1/produce() i 3 # 1&i 4 # 1&o 4 # 1 /approximate() start o 1 src i 1 copystore() copyapprox() copyinput() check() o 2 i 3 start i 4 o 4 approx consume() i 6 # 1/consume() i 1 # 1&o 2 # 1 /copystore() i 2 # 1&!check() &o 2 # 1 start /copyinput() loop i 2 # 1&check()&o 3 # 1 /copyapprox() i 6 o 3 i 2 o 6 sqrloop o 5 i 5 duplicate() i 5 # 1&o 5 # 1&o 6 # 1 /duplicate() start sink start dup graphical representation of a complete SysteMoC design Newton s iterative algorithm square root calculation Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 6

7 Introduction SysteMoC Concepts produce() approximate() o 1 # 1/produce() i 3 # 1&i 4 # 1&o 4 # 1 /approximate() start o 1 src i 1 copystore() copyapprox() copyinput() check() o 2 i 3 start i 4 o 4 approx consume() i 6 # 1/consume() i 1 # 1&o 2 # 1 /copystore() i 2 # 1&!check() &o 2 # 1 start /copyinput() loop i 2 # 1&check()&o 3 # 1 /copyapprox() i 6 o 3 i 2 o 6 sqrloop o 5 i 5 duplicate() i 5 # 1&o 5 # 1&o 6 # 1 /duplicate() start sink start dup actors have ports Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 6

8 Introduction SysteMoC Concepts produce() approximate() o 1 # 1/produce() i 3 # 1&i 4 # 1&o 4 # 1 /approximate() start o 1 src i 1 copystore() copyapprox() copyinput() check() o 2 i 3 start i 4 o 4 approx consume() i 6 # 1/consume() i 1 # 1&o 2 # 1 /copystore() i 2 # 1&!check() &o 2 # 1 start /copyinput() loop i 2 # 1&check()&o 3 # 1 /copyapprox() i 6 o 3 i 2 o 6 sqrloop o 5 i 5 duplicate() i 5 # 1&o 5 # 1&o 6 # 1 /duplicate() start sink start dup ports are connected to channels actors communication via channels only Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 6

9 Introduction SysteMoC Concepts produce() approximate() o 1 # 1/produce() i 3 # 1&i 4 # 1&o 4 # 1 /approximate() start o 1 src i 1 copystore() copyapprox() copyinput() check() o 2 i 3 start i 4 o 4 approx consume() i 6 # 1/consume() i 1 # 1&o 2 # 1 /copystore() i 2 # 1&!check() &o 2 # 1 start /copyinput() loop i 2 # 1&check()&o 3 # 1 /copyapprox() i 6 o 3 i 2 o 6 sqrloop o 5 i 5 duplicate() i 5 # 1&o 5 # 1&o 6 # 1 /duplicate() start sink start dup actions implement functionality of actors actions are written in C++ Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 6

10 Introduction SysteMoC Concepts produce() approximate() o 1 # 1/produce() i 3 # 1&i 4 # 1&o 4 # 1 /approximate() start o 1 src i 1 copystore() copyapprox() copyinput() check() o 2 i 3 start i 4 o 4 approx consume() i 6 # 1/consume() i 1 # 1&o 2 # 1 /copystore() i 2 # 1&!check() &o 2 # 1 start /copyinput() loop i 2 # 1&check()&o 3 # 1 /copyapprox() i 6 o 3 i 2 o 6 sqrloop o 5 i 5 duplicate() i 5 # 1&o 5 # 1&o 6 # 1 /duplicate() start sink start dup a finite state machine controls an actor the FSM defines communication behavior and triggers execution of actions Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 6

11 Introduction Actor Interaction Actor state active Actor FSM call passive Variables read modify Functions actions guards actors are composed of a Finite State Machine (FSM), functions, and variables the FSM controls the function invocation functions are executed atomically data consumption and production is performed at the end of an action execution Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 7

12 Introduction Simulation Semantics a transition is active if all referred input queues have enough tokens, all referred output queues have enough free space (places), and all guards are evaluated to true an active transition may be fired the associated action is executed consumption and production of data tokens take place data flow between actors may activate or deactivate actions if several transitions of one actor are active one transition is selected non-deterministically Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 8

13 Programming Examples

14 Hello World Objectives You will see a state-of-the-art Hello World application modeled in SysteMoC. Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 10

15 Hello World // file hello.cpp #include < iostream > #include < systemoc / smoc_moc.hpp > class HelloActor : public smoc_actor { public: // actor constructor HelloActor ( sc_module_name name) : smoc_actor ( name, start) { // FSM definition : // transition from start to end calling action src start = CALL( HelloActor :: src) >> end; } private: smoc_firing_state start, end; // FSM states void src () { // action std :: cout << " Actor " << this-> name () << " says :\ n" << " Hello World" << std :: endl; } }; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 11

16 Hello World // file hello. cpp cont d class HelloNetworkGraph : public smoc_graph { public: // network graph constructor HelloNetworkGraph ( sc_module_name name) : smoc_graph (name), helloactor (" HelloActor ") // create actor HelloActor { } private: // actors HelloActor helloactor ; }; int sc_main (int argc, char ** argv) { // create network graph HelloNetworkGraph top(" top"); smoc_scheduler_top sched( top); } sc_start (); // start simulation ( SystemC) return 0; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 12

17 Hello World compile the source code run simulation (OSCI SystemC: execute binary for simulation )./ hello simulation output SystemC Dec :10:07 Copyright (c) by all Contributors ALL RIGHTS RESERVED Actor top. HelloActor says: Hello World SystemC: simulation stopped by user. Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 13

18 Actors and Graphs Objectives You will learn to write actors.... instantiate actors in a network graph.... run functional simulation. Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 14

19 Actors and Graphs Actors include SysteMoC library header #include < systemoc / smoc_moc.hpp > an actor is a C++ class derived from base class smoc_actor class HelloActor : public smoc_actor { an action is a member function of the actors class actions shall be private prohibit execution by others private: void src () { // action std :: cout << " Actor " << this-> name () << " says :\ n" << " Hello World" << std :: endl; } Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 15

20 Actors and Graphs Actors an actor has a finite set of states smoc_firing_state state_a, state_b; // FSM states like objects of a class in C++, we create instances of an actor constructors are responsible for creating a certain actor instance provide actor name and start state to base class smoc_actor HelloActor ( sc_module_name name) // actor constructor : smoc_actor ( name, state_a) { Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 16

21 Actors and Graphs Actors a finite state machine (FSM) defines transitions between states e.g. a transition from state_a to state_b if this transition is taken, the action HelloActor::src is executed } HelloActor ( sc_module_name name) // actor constructor : smoc_actor ( name, state_a) { // FSM definition : // transition from state_a to state_b calling action src state_a = CALL( HelloActor :: src) >> state_b; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 17

22 Actors and Graphs Graphs a network graph is derived from base class smoc_graph class HelloNetworkGraph : public smoc_graph { our network graph has an instance of the HelloActor private: // actors HelloActor helloactor ; a name for the graph has to be passed to base class smoc_graph we need to call HelloActor s constructor // network graph constructor HelloNetworkGraph ( sc_module_name name) : smoc_graph (name), helloactor (" HelloActor ") // create actor HelloWorld { } }; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 18

23 Simulation function sc_main is the entry point for simulation (cf. SystemC) the network graph is instantiated parameters are passed to the graph constructor (e.g. top ) call sc_start to start simulation (cf. SystemC) int sc_main (int argc, char ** argv) { // create network graph HelloNetworkGraph top(" top"); smoc_scheduler_top sched( top); } sc_start (); // start simulation ( SystemC) return 0; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 19

24 Ports and Channels Objectives You will learn to use ports.... connect actors via channels. Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 20

25 Ports and Channels Sink Actor class Sink: public smoc_actor { public: // ports: smoc_port_in <char> in; Sink( sc_module_name name) // actor constructor : smoc_actor ( name, start) { // FSM definition : start = in (1) >> CALL(Sink :: sink) >> start; } private: smoc_firing_state start; // FSM states void sink () { std :: cout << this-> name () << " recv: \"" << in [0] << "\"" << std :: endl; } }; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 21

26 Ports and Channels Input Port create an input port ports have a data type (e.g. char) smoc_port_in <char> in; a single object of the particular data type is termed a token declare to read one token in FSM transition start = in (1) >> CALL(Sink :: sink) >> start; write data in action void sink () { std :: cout << this-> name () << " recv: \ " << in [0] << "\ " << std :: endl; } Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 22

27 Ports and Channels Source Actor using output ports is similar class Source: public smoc_actor { public: // ports: smoc_port_out <char> out; Source( sc_module_name name) : smoc_actor ( name, start) { start = out (1) >> CALL(Source :: src) >> start; } private: smoc_firing_state start; // FSM states void src () { std :: cout << this-> name () << " send: \ X\ " << std :: endl; out [0] = X ; } }; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 23

28 Ports and Channels Output Port create an output with data type char smoc_port_out <char> out; declare to write one token in FSM transition start = out (1) >> CALL(Source :: src) >> start; access data in action void src () { std :: cout << this-> name () << " send: \ X\ " << std :: endl; out [0] = X ; } Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 24

29 Ports and Channels Connect Actors class NetworkGraph : public smoc_graph { public: NetworkGraph ( sc_module_name name) // network graph constructor : smoc_graph (name), source(" Source"), // create actors sink("sink") { connectnodeports ( source.out, sink. in); // connect } private: Source source; // actors Sink sink; }; actors int sc_main (int argc, char ** argv) { smoc_top_moc < NetworkGraph > top(" top"); // create network graph } sc_start (); // start simulation ( SystemC) return 0; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 25

30 Ports and Channels FIFO Queues connect a pair of ports (input, output) using a FIFO queue connected ports have to use the same data type queues have default size 1 (one data token) connectnodeports ( source.out, sink. in); set queue size explicitly connectnodeports <23 >( source.out, sink. in); more advanced channel features (later) channel types initial data tokens Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 26

31 Ports and Channels simulation output SystemC Dec :10:07 Copyright (c) by all Contributors ALL RIGHTS RESERVED top.source send: X top.sink recv: X top.source send: X top.sink recv: X top.source send: X top.sink recv: X... simulation runs infinitely Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 27

32 Guards and Actions Objectives You will learn to write and use guards.... write and use actions. Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 28

33 Guards and Actions SourceActor static const std :: string MESSAGE = " "; class Source: public smoc_actor { public: smoc_port_out <char> out; Source( sc_module_name name) : smoc_actor ( name, start), count (0), size(message.size ()), message(message) { start = GUARD(Source :: hastoken ) >> out (1) >> CALL(Source :: src) >> start; } private: smoc_firing_state start; unsigned int count, size; // variables ( functional state) const std :: string message; // bool hastoken () const{ return count < size; } // guard void src () { out [0] = message[ count ++]; } // action }; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 29

34 Guards and Actions Guards a guard is a const member function returning a boolean value bool hastoken () const{ return count < size; } // guard guards enable/disable transitions (true/false) guards must (can) not change variable values or token in channels refer to guards via GUARD(..) macro start = GUARD(Source :: hastoken ) >> out (1) >> CALL(Source :: src) >> start; use guards for control flow (see below) Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 30

35 Guards and Actions Variables variables are private class member of an actor... can be used to store data... represent a functional state of an actor (in contrast to FSM state) unsigned int count, size; const std :: string message; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 31

36 Guards and Actions Actions actions are used to read/write data on input/output ports... modify variables void src () { out [0] = message[ count ++]; } guards access variables read-only (mandatory const modifier) actions are allowed to modify variables Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 32

37 Guards and Actions Multiple Access you can write/read data more than once (overwrite/re-read) e.g. read input twice void sink () { char squareinput = in [0] * in [0]; } char x = in [0]; char y = in [0]; // re -read assert(x == y); e.g. write a default value first void src () { out [0] = X ; // default if(count <size){ out [0] = message[ count ++]; // overwrite } } Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 33

38 Guards and Actions simulation output (using Sink actor from previous example) top. Sink recv: "0" top. Sink recv: "1" top. Sink recv: "2" top. Sink recv: "3" top. Sink recv: "4" top. Sink recv: "5" top. Sink recv: "6" top. Sink recv: "7" top. Sink recv: "8" top. Sink recv: "9" SystemC: simulation stopped by user. Source actor sends a finite number of characters only simulation terminates when no actor can be activated Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 34

39 Communication Rates Objectives former examples consume/produce only a single token per invocation consumption and production rates may be different from one You will learn to use consumption and production rates. Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 35

40 Communication Rates Source Actor static const std :: string MESSAGE = " "; class Source: public smoc_actor { public: smoc_port_out <char> out; Source( sc_module_name name) : smoc_actor ( name, start), count (0), size(strlen(message)), message(message) { start = GUARD(Source :: hastoken ) >> } private: out (2) >> CALL(Source :: src) >> start; smoc_firing_state start; unsigned int count, size; // variables ( functional state) const char* message; // bool hastoken () const{ return count < size; } // guard void src () { // action out [0] = message[ count ++]; out [1] = message[ count ++]; }}; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 36

41 Communication Rates Production Rate the Source actor produces two data tokens per invocation we declare to produce n data tokens in a transition using out(n) start = GUARD(Source :: hastoken ) >> out (2) >> CALL(Source :: src) >> start; use the index operator [] to write data values void src () { out [0] = message[ count ++]; out [1] = message[ count ++]; } similar to arrays addressing range is 0,...,n 1 Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 37

42 Communication Rates Avoid Deadlocks simulation output (using Sink actor from previous example) SystemC Dec :10:07 Copyright (c) by all Contributors ALL RIGHTS RESERVED SystemC: simulation stopped by user. Oh oh, nothing happens! writing two tokens requires free space for (at least) two tokens we need to increase the queue size (implicit size was 1 ) connectnodeports <4>( source.out, sink.in); minimum size of 2 is mandatory (but actors would run in lockstep) using larger sized queues may decouple execution of actors Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 38

43 Communication Rates Simulation simulation output (using Sink actor from previous example) and increased queue size SystemC Dec :10:07 Copyright (c) by all Contributors ALL RIGHTS RESERVED top. Sink recv: "0" top. Sink recv: "1" top. Sink recv: "2" top. Sink recv: "3" top. Sink recv: "4" top. Sink recv: "5" top. Sink recv: "6" top. Sink recv: "7" top. Sink recv: "8" top. Sink recv: "9" SystemC: simulation stopped by user. Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 39

44 Communication Rates Queue Access Source Sink void produce(){ out[0] = x; out[2] = y; } void consume(){ int a = in[0]; } out(3) /produce() out out[2] out[1] out[0] in[1] in[0] in in(2) /consume() read tokens... a transition claims to consume n tokens from input port in using in(n) read data from FIFO queue using in[j]; j 0,...,n 1 in[0] refers first available token in queue Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 40

45 Communication Rates Queue Access Source Sink void produce(){ out[0] = x; out[2] = y; } void consume(){ int a = in[0]; } out(3) /produce() out out[2] out[1] out[0] in[1] in[0] in in(2) /consume() write tokens... a transition claims to produce n tokens on output port out using out(n) write data to FIFO queue using out[j]; j 0,...,n 1 out[0] refers first free position (place) in a queue Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 40

46 Communication Rates Queue Access Source Sink void produce(){ out[0] = x; out[2] = y; } void consume(){ int a = in[0]; } out(3) /produce() out out[2] out[1] out[0] in[1] in[0] in in(2) /consume() activation and execution... transition becomes active (enough token, free space; guards) an activated transition may be fired firing a transition implies execution of its action Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 40

47 Initial Tokens Objectives data flow graphs may contain cyclic dependencies initial tokens are a common way to break cyclic dependencies You will learn to initialize queues. Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 41

48 Initial Tokens Cyclic Dependencies forward() in out forward() in(1)&&out(1)/forward() in(1)&&out(1)/forward() out in start Ping Pong start each actor forwards input tokens to output port network graph contains a cyclic dependency without initialization none of the actors would become active we may use an initial token to break the cyclic dependency Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 42

49 Initial Tokens Example class Forward: public smoc_actor { public: smoc_port_in <int> in; smoc_port_out <int> out; Forward( sc_module_name start = in (1) >> out (1) >> CALL(Forward :: forward) >> start; } private: smoc_firing_state start; name) : smoc_actor ( name, start){ void forward () { std :: cout << this-> name () << " forward: \"" << in [0] << "\"" << std :: endl; out [0] = in [0]; } }; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 43

50 Initial Tokens Example class NetworkGraph : public smoc_graph { protected: // actors Forward ping; Forward pong; public: // network graph constructor NetworkGraph ( sc_module_name name) : smoc_graph (name), // create actors ping("ping"), pong("pong") { } }; smoc_fifo <int> initfifo (1); initfifo << 42; connectnodeports (ping.out, pong.in); connectnodeports ( pong.out, ping.in, initfifo ); Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 44

51 Initial Tokens Simulation SystemC Dec :10:07 Copyright (c) by all Contributors ALL RIGHTS RESERVED top.ping forward: "42" top.pong forward: "42" top.ping forward: "42" top.pong forward: "42"... Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 45

52 Initial Tokens Syntax explicit creation of a FIFO initializer give queue size as constructor parameter smoc_fifo <int> initfifo (1); push initial value to initializer initfifo << 42; pass initializer when constructing the queue connectnodeports ( pong.out, ping.in, initfifo ); initializer may be reused for creating identical initialized queues Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 46

53 Advanced Data Flow Modeling

54 Hierarchical States Objectives You will learn how to refine states of an FSM into hierarchical states by means of XOR decomposition,... AND decomposition, and... Junction states Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 48

55 Non-Hierarchical Example #include < iostream > #include < systemoc / smoc_moc.hpp > class Actor : public smoc_actor { public: enum CmdType { CMD_GO, CMD_STOP }; smoc_port_in < CmdType > inctl; Actor( sc_module_name name) : smoc_actor ( name, stopped) { smoc_firing_state run; // states can be declared locally stopped = inctl (1) && GUARD(Actor :: iscmd)(cmd_go) >> CALL(Actor ::go) >> run; run = inctl (1) && GUARD( Actor :: iscmd)( CMD_STOP ) >> CALL(Actor :: stop) >> stopped; }... Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 49

56 Non-Hierarchical Example... private: smoc_firing_state stopped; bool iscmd( CmdType cmd) const { return inctl [0] == cmd; } void go() { std :: cout << this-> name () << ": Go" << std :: endl; } void stop () { std :: cout << this-> name () << ": Stop" << std :: endl; } }; This initial example contains two non-hierarchical states stopped and run as known from previous examples Note that states (except the initial state) can be declared locally inside the constructor In the following, we will refine the run state into a nested FSM by means of hierarchical states Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 50

57 Hierarchical States XOR decomposition First step: Replace the type of a state by the desired hierarchical state type, namely smoc_xor_state or smoc_and_state. In this example, we will refine the run state into an XOR state: Actor (...) : smoc_actor (..., stopped) { smoc_xor_state run;... } Second step: Instantiate the child states of the XOR state. Note that these can consist of hierarchical and non-hierarchical states:... smoc_xor_state run; smoc_firing_state waitmsg; smoc_and_state storedata ; // will be refined later smoc_firing_state sendack;... Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 51

58 Hierarchical States XOR decomposition Third step: Add the child states to the XOR state. Note that the initial child state, i.e., the state which should be active when the XOR state is entered, must be added via parent.init(child). All other states are added via parent.add(child): smoc_xor_state run; smoc_firing_state waitmsg; // initial child state smoc_and_state storedata ; smoc_firing_state sendack; run.init(waitmsg); run.add( storedata ); run.add(sendack); Last step: Add transitions to the child states: waitmsg = inlink (1) >> CALL( Actor :: processmsg ) >> storedata ; sendack = outlink (1) >> CALL( Actor :: sendackmsg ) >> waitmsg; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 52

59 Hierarchical States XOR decomposition XOR states must have exactly one initial state States which are not added to any hierarchical state are automatically added to the FSM (like stopped and run in this example), which can also be seen as an XOR state (with stopped being the initial state in this example) Transitions added to the XOR state itself are added (recursively) to all child states. In this case, the only outgoing transition of the run state allows for leaving the receive/send loop at any time: run = inctl (1) && GUARD( Actor :: iscmd)( CMD_STOP ) >> CALL(Actor :: stop) >> stopped; History connectors are not supported at this time Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 53

60 Hierarchical States AND decomposition An XOR state has exactly one active child state at any one time In an AND state, all child states are active at any one time. In the following, the child states of an AND state will be called partitions A partition can be a hierarchical or non-hierarchical state The state of an AND state with N partitions P 1,...,P N is given by the tuple (s 1,s 2,...,s N ), such that i,1 i N : s i is a valid state from partition P i. This is also called a product state The initial state of an AND state is the product state whose components are in turn the initial states of the corresponding partitions In SysteMoC, an AND state can be declared as follows: smoc_and_state storedata ; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 54

61 Hierarchical States AND decomposition Partitions are added to AND states in the same manner as child states are added to XOR states: smoc_and_state storedata ; smoc_xor_state senddmawritereqs ; smoc_xor_state recvdmawriteacks ; // add two partitions to storedata : storedata. add( senddmawritereqs ). add( recvdmawriteacks ); // add child states to the first partition : smoc_firing_state senddmawritereq ; smoc_firing_state sentalldmawritereqs ; senddmawritereqs. init( senddmawritereq ). add( sentalldmawritereqs ); // add child states to the second partition : smoc_firing_state recvdmawriteack ; smoc_firing_state recvdalldmawriteacks ; recvdmawriteacks. init( recvdmawriteack ). add( recvdalldmawriteacks ); Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 55

62 Hierarchical States AND decomposition Transitions can be added to partitions as usual. Note that transitions between partitions are not allowed: senddmawritereq = outmem (1) && GUARD( Actor :: sendmoredmawritereqs ) >> CALL( Actor :: senddmawritereq ) >> senddmawritereq! GUARD( Actor :: sendmoredmawritereqs ) >> sentalldmawritereqs ; recvdmawriteack = inmem (1) && GUARD( Actor :: isdmawriteack ) >> CALL( Actor :: processdmawriteack ) >> recvdmawriteack! GUARD( Actor :: pendingdmawriteacks ) >> recvdalldmawriteacks ; // not allowed ( will throw a ModelingException ): // senddmawritereq =... >> recvdmawriteack ; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 56

63 Hierarchical States AND decomposition A transition whose target state is an AND state may specify for each partition which state should be active when entering the AND state: waitmsg = inlink (1) >> CALL( Actor :: processmsg ) >> ( senddmawritereq, recvdmawriteack ); If no specific state is given for a partition, the default initial state will be the active state: waitmsg = inlink (1) >> CALL( Actor :: processmsg ) >> storedata ; Both transitions are equivalent, as both senddmawritereq and recvdmawriteack are the initial states of their corresponding partitions In fact, the target state can be any valid (partial) product state Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 57

64 Hierarchical States AND decomposition It is also possible for the source state to be a (partial) product state. However, some restrictions apply A transition must be appended to exactly one state. All other states in the (partial) product state must be marked with the IN keyword: (s1, IN(s2), IN(s3),...) =...; In this case, the transition from s1 will be enabled if the FSM is also in states s2 and s3. The IN keyword can also be negated: (s1, IN(s2),!IN(s3),...) =...; In this case, the transition from s1 will be enabled if the FSM is in state s2 but not in s3. Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 58

65 Hierarchical States AND decomposition Like an XOR state, an AND state will be left if the target state of a transition is no child state of the AND state... ( sentalldmawritereqs, IN( recvdalldmawriteacks )) =... >> sendack...or if the source state of a transition is the AND state itself: ( storedata, IN( sentalldmawritereqs ), IN( recvdalldmawriteacks )) =... >> sendack Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 59

66 Hierarchical States Junction states Junction states as known from UML can be used to chain together multiple transitions They are not part of the state hierarchy and need not be added to any states smoc_firing_state a, b, c; smoc_junction_state j; a = CALL( Actor :: actiona) >> j; b = CALL( Actor :: actionb) >> j; j = CALL( Actor :: actionc) >> c; This example is equivalent to the following FSM fragment without junction states: smoc_firing_state a, b, c; a = CALL(Actor :: actiona) >> CALL(Actor :: actionc) >> c; b = CALL(Actor :: actionb) >> CALL(Actor :: actionc) >> c; Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 60

67 Hierarchical States Junction states Note that a transition can have multiple actions. In this case, the order of execution is equal to the order of appearance All pairs (t in,t out ) of transitions where t in is a transition entering the junction state and t out is a transition leaving the junction state will be transformed into a single compound transition Actions of transition t in will be executed prior to the actions of transition t out All guards of a compound transition are executed prior to any action of a compound transition For example, if variables are modified by transition t in, guards of transition t out will see the old values of these variables, and not the modified values The port requirements of t in and t out should be disjoint at this time. However, the actions of t out can access tokens required by t in and vice versa Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 61

68 Dynamic FSM Construction Objectives You will learn how to dynamically construct the FSM of an actor by dynamically adding transitions to states and... by passing and returning states to and from functions Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 62

69 Dynamic FSM Construction Transitions can be added to states after some transitions have already been added: smoc_firing_state a, b, c, d; // overwrite any transitions already added to a a = GUARD(Actor :: guarda) >> CALL(Actor :: actiona) >> a GUARD(Actor :: guardb) >> CALL(Actor :: actionb) >> b; // append some more transitions to a a = GUARD(Actor :: guardc) >> CALL(Actor :: actionc) >> c GUARD(Actor :: guardd) >> CALL(Actor :: actiond) >> d; Note that whereas a = <transition list> first removes all transitions from a and then adds <transition list> to a, a = <transition list> simply appends <transition list> to a Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 63

70 Dynamic FSM Construction States can be passed to functions via pointers or references: void a( smoc_firing_state & s); void b( smoc_firing_state :: Ref s); // equivalent to a void c(const smoc_firing_state & s); void d( smoc_firing_state :: ConstRef s); // equivalent to c void e( smoc_firing_state * a); void f( smoc_firing_state :: Ptr a); // equivalent to e void g(const smoc_firing_state * a); void h( smoc_firing_state :: ConstPtr a); // equivalent to g Due to states being reference counted, using ::Ref, ::ConstRef, ::Ptr and ::ConstPtr is the preferred way of passing around references or pointers to states Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 64

71 Dynamic FSM Construction States can be returned from functions via pointers or references: smoc_firing_state :: Ptr a() { smoc_firing_state s;... return &s; } smoc_firing_state :: Ref b() { smoc_firing_state s;... return s; } Note that when using ::Ref, ::ConstRef, ::Ptr or ::ConstPtr as the return type of a function, returning a pointer or reference to a state declared locally inside the function is perfectly legal Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 65

72 Remarks

73 Outline Introduction Programming Examples Advanced Data Flow Modeling Remarks Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 67

74 Contact Contact Persons: Joachim Falk, Jürgen Teich Address: Hardware/Software Co-Design Department of Computer Science University of Erlangen-Nuremberg Cauerstr Erlangen, Germany Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 68

75 Credits SysteMoC Development Team: Joachim Falk, Jens Gladigau, Martin Streubühr, Christian Zebelein SystemCoDesigner Contributors: Joachim Falk, Michael Glass, Jens Gladigau, Joachim Keinert, Martin Lukasiewycz, Felix Reimann, Thomas Schlichter, Thilo Streichert, Martin Streubühr, Christian Zebelein, Christian Haubelt, Jürgen Teich Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 69

76 Document Info Authors: Martin Streubühr, Christian Zebelein, Christian Haubelt, Joachim Falk Document Release: Jul. 3, 2012 Version History: Jul. 3, 2012: Version 1.2 Jul. 28, 2010: Version 1.1 Oct.1, 2009: Version 1.0 Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 70

77 Index actions, 36 actor, CALL, 21 connectnodeports, 29 30, 42 FIFO queue, FSM, 21 GUARD, 34 guard, 34 input port, 26 network graph, 22 output port, 28 port, 25 28, 37 simulation, 12, 23 smoc_actor, 19, 20 smoc_firing_state, 20 smoc_graph, 22 state, 20 variables, 35 Version 1.2 Martin Streubühr et al. FAU SystemCoDesigner: System Programming Tutorial 71

SystemCoDesigner: Performance Modeling Tutorial

SystemCoDesigner: Performance Modeling Tutorial SystemCoDesigner: Performance Modeling Tutorial Martin Streubühr Sebastian Graf Hardware/Software Co-Design Department of Computer Science University of Erlangen-Nuremberg Germany Version 1.4 Christian

More information

SysteMoC. Verification and Refinement of Actor-Based Models of Computation

SysteMoC. Verification and Refinement of Actor-Based Models of Computation SysteMoC Verification and Refinement of Actor-Based Models of Computation Joachim Falk, Jens Gladigau, Christian Haubelt, Joachim Keinert, Martin Streubühr, and Jürgen Teich {falk, haubelt}@cs.fau.de Hardware-Software-Co-Design

More information

Automatic Generation of System-Level Virtual Prototypes from Streaming Application Models

Automatic Generation of System-Level Virtual Prototypes from Streaming Application Models Automatic Generation of System-Level Virtual Prototypes from Streaming Application Models Philipp Kutzer, Jens Gladigau, Christian Haubelt, and Jürgen Teich Hardware/Software Co-Design, Department of Computer

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 10 October 1, 2018 CPSC 427, Lecture 10, October 1, 2018 1/20 Brackets Example (continued from lecture 8) Stack class Brackets class Main

More information

METROII AND PTOLEMYII INTEGRATION. Presented by: Shaoyi Cheng, Tatsuaki Iwata, Brad Miller, Avissa Tehrani

METROII AND PTOLEMYII INTEGRATION. Presented by: Shaoyi Cheng, Tatsuaki Iwata, Brad Miller, Avissa Tehrani METROII AND PTOLEMYII INTEGRATION Presented by: Shaoyi Cheng, Tatsuaki Iwata, Brad Miller, Avissa Tehrani INTRODUCTION PtolemyII is a tool for design of component-based systems using heterogeneous modeling

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

Variables. Data Types.

Variables. Data Types. Variables. Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting

More information

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming

More information

Input And Output of C++

Input And Output of C++ Input And Output of C++ Input And Output of C++ Seperating Lines of Output New lines in output Recall: "\n" "newline" A second method: object endl Examples: cout

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 7 September 21, 2016 CPSC 427, Lecture 7 1/21 Brackets Example (continued) Storage Management CPSC 427, Lecture 7 2/21 Brackets Example

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

CS 376b Computer Vision

CS 376b Computer Vision CS 376b Computer Vision 09 / 25 / 2014 Instructor: Michael Eckmann Today s Topics Questions? / Comments? Enhancing images / masks Cross correlation Convolution C++ Cross-correlation Cross-correlation involves

More information

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

More information

Some notes about Event-B and Rodin

Some notes about Event-B and Rodin Some notes about Event-B and Rodin Résumé This document briefly presents the language event-b and the tool Rodin. For a comprehensive presentation, refer to the event-b page http://www.event-b.org/, the

More information

Throughput-optimizing Compilation of Dataflow Applications for Multi-Cores using Quasi-Static Scheduling

Throughput-optimizing Compilation of Dataflow Applications for Multi-Cores using Quasi-Static Scheduling Throughput-optimizing Compilation of Dataflow Applications for Multi-Cores using Quasi-Static Scheduling Tobias Schwarzer 1, Joachim Falk 1, Michael Glaß 1, Jürgen Teich 1, Christian Zebelein 2, Christian

More information

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am CMSC 202 Section 010x Spring 2007 Computer Science II Final Exam Name: Username: Score Max Section: (check one) 0101 - Justin Martineau, Tuesday 11:30am 0102 - Sandeep Balijepalli, Thursday 11:30am 0103

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching

More information

AN OVERVIEW OF C++ 1

AN OVERVIEW OF C++ 1 AN OVERVIEW OF C++ 1 OBJECTIVES Introduction What is object-oriented programming? Two versions of C++ C++ console I/O C++ comments Classes: A first look Some differences between C and C++ Introducing function

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

Semantics of C++ Hauptseminar im Wintersemester 2009/10 Templates

Semantics of C++ Hauptseminar im Wintersemester 2009/10 Templates Semantics of C++ Hauptseminar im Wintersemester 2009/10 Templates Sebastian Wild Technische Universität München 11.01.2010 Abstract In this work we will discuss about templates in C++, especially their

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Midterm Review. PIC 10B Spring 2018

Midterm Review. PIC 10B Spring 2018 Midterm Review PIC 10B Spring 2018 Q1 What is size t and when should it be used? A1 size t is an unsigned integer type used for indexing containers and holding the size of a container. It is guarenteed

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

More information

COMP 2355 Introduction to Systems Programming

COMP 2355 Introduction to Systems Programming COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Today Class syntax, Constructors, Destructors Static methods Inheritance, Abstract

More information

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. CMPSC11 Final (Study Guide) Fall 11 Prof Hartman Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) This is a collection of statements that performs

More information

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name:  ID: Page 1 of 10 Name: Email ID: You MUST write your name and e-mail ID on EACH page and bubble in your userid at the bottom of EACH page including this page and page 10. If you do not do this, you will receive

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 5 February 2, 2016 CPSC 427, Lecture 5 1/31 C++ I/O (continued) End of File and I/O Errors Functions and Methods Parameters Choosing Parameter

More information

Actor-oriented Modeling and Simulation of Cut-through Communication in Network Controllers

Actor-oriented Modeling and Simulation of Cut-through Communication in Network Controllers In Proceedings of Methoden und Beschreibungssprachen zur Modellierung und Verifikation von Schaltungen und Systemen (MBMV), Kaiserslautern, Germany, March 05-07, 2012 Actor-oriented Modeling and Simulation

More information

Advanced Systems Programming

Advanced Systems Programming Advanced Systems Programming Introduction to C++ Martin Küttler September 19, 2017 1 / 18 About this presentation This presentation is not about learning programming or every C++ feature. It is a short

More information

Linked List using a Sentinel

Linked List using a Sentinel Linked List using a Sentinel Linked List.h / Linked List.h Using a sentinel for search Created by Enoch Hwang on 2/1/10. Copyright 2010 La Sierra University. All rights reserved. / #include

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence

More information

C++ Programming: Polymorphism

C++ Programming: Polymorphism C++ Programming: Polymorphism 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering Contents Run-time binding in C++ Abstract base classes Run-time type identification 2 Function

More information

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi Modern C++ for Computer Vision and Image Processing Igor Bogoslavskyi Outline Static variables and methods Representation of numbers in memory Raw C arrays Non-owning pointers in C++ Classes in memory

More information

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings 19/10/2017 CE221 Part 2 1 Variables and References 1 In Java a variable of primitive type is associated with a memory location

More information

CS2141 Software Development using C/C++ C++ Basics

CS2141 Software Development using C/C++ C++ Basics CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short

More information

Introduction to Programming using C++

Introduction to Programming using C++ Introduction to Programming using C++ Lecture One: Getting Started Carl Gwilliam gwilliam@hep.ph.liv.ac.uk http://hep.ph.liv.ac.uk/~gwilliam/cppcourse Course Prerequisites What you should already know

More information

Chapter 15 - C++ As A "Better C"

Chapter 15 - C++ As A Better C Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference

More information

Course "Data Processing" Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1

Course Data Processing Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1 Examen - Part A Page 1 1. mydir directory contains three files: filea.txt fileb.txt filec.txt. How many files will be in the directory after performing the following operations: $ ls filea.txt fileb.txt

More information

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things. A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators

More information

Polymorphism Part 1 1

Polymorphism Part 1 1 Polymorphism Part 1 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid

More information

Lecture 7. Log into Linux New documents posted to course webpage

Lecture 7. Log into Linux New documents posted to course webpage Lecture 7 Log into Linux New documents posted to course webpage Coding style guideline; part of project grade is following this Homework 4, due on Monday; this is a written assignment Project 1, due next

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab. University of Technology Laser & Optoelectronics Engineering Department C++ Lab. Second week Variables Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable.

More information

Chapter 2. Procedural Programming

Chapter 2. Procedural Programming Chapter 2 Procedural Programming 2: Preview Basic concepts that are similar in both Java and C++, including: standard data types control structures I/O functions Dynamic memory management, and some basic

More information

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value Paytm Programming Sample paper: 1) A copy constructor is called a. when an object is returned by value b. when an object is passed by value as an argument c. when compiler generates a temporary object

More information

A System-Level Synthesis Approach from Formal Application Models to Generic Bus-Based MPSoCs

A System-Level Synthesis Approach from Formal Application Models to Generic Bus-Based MPSoCs A System-Level Synthesis Approach from Formal Application s to Generic Bus-Based MPSoCs Jens Gladigau 1, Andreas Gerstlauer 2, Christian Haubelt 1, Martin Streubühr 1, and Jürgen Teich 1 1 Department of

More information

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. 1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. B. Outputs to the console a floating point number f1 in scientific format

More information

visualstate Reference Guide

visualstate Reference Guide COPYRIGHT NOTICE Copyright 2000 2014 IAR Systems AB. No part of this document may be reproduced without the prior written consent of IAR Systems. The software described in this document is furnished under

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

Modeling Software with SystemC 3.0

Modeling Software with SystemC 3.0 Modeling Software with SystemC 3.0 Thorsten Grötker Synopsys, Inc. 6 th European SystemC Users Group Meeting Stresa, Italy, October 22, 2002 Agenda Roadmap Why Software Modeling? Today: What works and

More information

cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers.

cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers. cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... today: language basics: identifiers, data types, operators, type conversions, branching and looping, program structure

More information

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

COEN244: Class & function templates

COEN244: Class & function templates COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library

More information

CS242 COMPUTER PROGRAMMING

CS242 COMPUTER PROGRAMMING CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing

More information

CSE143 Exam with answers MIDTERM #1, 1/26/2001 Problem numbering may differ from the test as given.

CSE143 Exam with answers MIDTERM #1, 1/26/2001 Problem numbering may differ from the test as given. CSE143 Exam with answers MIDTERM #1, 1/26/2001 Problem numbering may differ from the test as given. All multiple choice questions are equally weighted. You can generally assume that code shown in the questions

More information

Process and data flow modeling

Process and data flow modeling Process and data flow modeling Vince Molnár Informatikai Rendszertervezés BMEVIMIAC01 Budapest University of Technology and Economics Fault Tolerant Systems Research Group Budapest University of Technology

More information

COMP-520 GoLite Tutorial

COMP-520 GoLite Tutorial COMP-520 GoLite Tutorial Alexander Krolik Sable Lab McGill University Winter 2019 Plan Target languages Language constructs, emphasis on special cases General execution semantics Declarations Types Statements

More information

CS302 - Data Structures using C++

CS302 - Data Structures using C++ CS302 - Data Structures using C++ Pre-Course: Variables, Basic Types, Control Structures Kostas Alexis Slides inspired by the course Modern C++, Uni Bonn: http://www.ipb.uni-bonn.de/teaching/modern-cpp/

More information

W3101: Programming Languages C++ Ramana Isukapalli

W3101: Programming Languages C++ Ramana Isukapalli Lecture-6 Operator overloading Namespaces Standard template library vector List Map Set Casting in C++ Operator Overloading Operator overloading On two objects of the same class, can we perform typical

More information

2 nd Week Lecture Notes

2 nd Week Lecture Notes 2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous

More information

Lab 1: First Steps in C++ - Eclipse

Lab 1: First Steps in C++ - Eclipse Lab 1: First Steps in C++ - Eclipse Step Zero: Select workspace 1. Upon launching eclipse, we are ask to chose a workspace: 2. We select a new workspace directory (e.g., C:\Courses ): 3. We accept the

More information

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi and Cyrill Stachniss

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi and Cyrill Stachniss Modern C++ for Computer Vision and Image Processing Igor Bogoslavskyi and Cyrill Stachniss Outline Intro to C++ Variables and basic types Built-in types Strings Vector and array Control structures If statement

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information

Inheritance and Interfaces

Inheritance and Interfaces Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical

More information

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam Multimedia Programming 2004 Lecture 2 Erwin M. Bakker Joachim Rijsdam Recap Learning C++ by example No groups: everybody should experience developing and programming in C++! Assignments will determine

More information

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( )

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( ) Systems Group Department of Computer Science ETH Zürich Tutorial 1: Introduction to C Computer Architecture and Systems Programming (252-0061-00) Herbstsemester 2012 Goal Quick introduction to C Enough

More information

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309 A Arithmetic operation floating-point arithmetic, 11 12 integer numbers, 9 11 Arrays, 97 copying, 59 60 creation, 48 elements, 48 empty arrays and vectors, 57 58 executable program, 49 expressions, 48

More information

Function Overloading

Function Overloading Function Overloading C++ supports writing more than one function with the same name but different argument lists How does the compiler know which one the programmer is calling? They have different signatures

More information

CSCE 121 ENGR 112 List of Topics for Exam 1

CSCE 121 ENGR 112 List of Topics for Exam 1 List of Topics for Exam 1 If statements o How is an if statement constructed? o Does every if need an else? Looping o While loop! What does a while loop look like?! How do you ensure you will not have

More information

C++ Important Questions with Answers

C++ Important Questions with Answers 1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children

More information

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

double d0, d1, d2, d3; double * dp = new double[4]; double da[4]; All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers

More information

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles Abstract Data Types (ADTs) CS 247: Software Engineering Principles ADT Design An abstract data type (ADT) is a user-defined type that bundles together: the range of values that variables of that type can

More information

Why Is Repetition Needed?

Why Is Repetition Needed? Why Is Repetition Needed? Repetition allows efficient use of variables. It lets you process many values using a small number of variables. For example, to add five numbers: Inefficient way: Declare a variable

More information

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++ CSCE 206: Structured Programming in C++ 2017 Spring Exam 2 Monday, March 20, 2017 Total - 100 Points B Instructions: Total of 13 pages, including this cover and the last page. Before starting the exam,

More information

C++ for Python Programmers

C++ for Python Programmers C++ for Python Programmers Adapted from a document by Rich Enbody & Bill Punch of Michigan State University Purpose of this document This document is a brief introduction to C++ for Python programmers

More information

Exceptions, Case Study-Exception handling in C++.

Exceptions, Case Study-Exception handling in C++. PART III: Structuring of Computations- Structuring the computation, Expressions and statements, Conditional execution and iteration, Routines, Style issues: side effects and aliasing, Exceptions, Case

More information

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program: Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams

More information

Instantiation of Template class

Instantiation of Template class Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double

More information

AC OB S. Multi-threaded FW framework (OS) for embedded ARM systems Torsten Jaekel, June 2014

AC OB S. Multi-threaded FW framework (OS) for embedded ARM systems Torsten Jaekel, June 2014 AC OB S Multi-threaded FW framework (OS) for embedded ARM systems Torsten Jaekel, June 2014 ACOBS ACtive OBject (operating) System Simplified FW System for Multi-Threading on ARM embedded systems ACOBS

More information

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Inheritance Consider a new type Square. Following how we declarations for the Rectangle and Circle classes we could declare it as follows:

More information

Object Oriented Programming. Solved MCQs - Part 2

Object Oriented Programming. Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 It is possible to declare as a friend A member function A global function A class All of the above What

More information

Scientific Computing

Scientific Computing Scientific Computing Martin Lotz School of Mathematics The University of Manchester Lecture 1, September 22, 2014 Outline Course Overview Programming Basics The C++ Programming Language Outline Course

More information

Computer Programming : C++

Computer Programming : C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program

More information

Problem Solving with C++

Problem Solving with C++ GLOBAL EDITION Problem Solving with C++ NINTH EDITION Walter Savitch Kendrick Mock Ninth Edition PROBLEM SOLVING with C++ Problem Solving with C++, Global Edition Cover Title Copyright Contents Chapter

More information

Exercise 1.1 Hello world

Exercise 1.1 Hello world Exercise 1.1 Hello world The goal of this exercise is to verify that computer and compiler setup are functioning correctly. To verify that your setup runs fine, compile and run the hello world example

More information

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors CSC 330 OO Software Design 1 Abstract Base Classes class B { // base class virtual void m( ) =0; // pure virtual

More information

An abstract tree stores data that is hierarchically ordered. Operations that may be performed on an abstract tree include:

An abstract tree stores data that is hierarchically ordered. Operations that may be performed on an abstract tree include: 4.2 Abstract Trees Having introduced the tree data structure, we will step back and consider an Abstract Tree that stores a hierarchical ordering. 4.2.1 Description An abstract tree stores data that is

More information

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Cpt S 122 Data Structures. Course Review Midterm Exam # 2 Cpt S 122 Data Structures Course Review Midterm Exam # 2 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 2 When: Monday (11/05) 12:10 pm -1pm

More information

1. The term STL stands for?

1. The term STL stands for? 1. The term STL stands for? a) Simple Template Library b) Static Template Library c) Single Type Based Library d) Standard Template Library Answer : d 2. Which of the following statements regarding the

More information

CS 247: Software Engineering Principles. ADT Design

CS 247: Software Engineering Principles. ADT Design CS 247: Software Engineering Principles ADT Design Readings: Eckel, Vol. 1 Ch. 7 Function Overloading & Default Arguments Ch. 12 Operator Overloading U Waterloo CS247 (Spring 2017) p.1/17 Abstract Data

More information

C - Basics, Bitwise Operator. Zhaoguo Wang

C - Basics, Bitwise Operator. Zhaoguo Wang C - Basics, Bitwise Operator Zhaoguo Wang Java is the best language!!! NO! C is the best!!!! Languages C Java Python 1972 1995 2000 (2.0) Procedure Object oriented Procedure & object oriented Compiled

More information

Pointers, Dynamic Data, and Reference Types

Pointers, Dynamic Data, and Reference Types Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple

More information