Lecture 3

Review

   resources -- variables, procedures, processes
   procedures
   declarations -- var name: type := expression
   guarded commands and for-all statements


Today:  concurrent execution in SR

   when:  independent parts of programs

   why:  separate tasks    -- multithreaded
         speedup           -- parallel
         separate machines -- distributed

   how:  co statement and process declaration


Concurrent Statement in SR
 
   co invocation1 // ... // invocationN oc

   invocation:  procedure or function call

   meaning of co:  start all calls (fork), wait for them to return (join),
      then go on to execute the next statement

   a co statement creates (forks, spawns) n *new* processes (threads)


Process Delcaration

   process name
      body               declarations and statements
   end
             
   process name(quantifiers)
      body
   end

   first form specifies a single process; second form an array of processes

   a process is forked when its declaration is encountered
   the main process (of the enclosing resource) *does not wait*
      it goes on to the next statement or declaration


Examples (using transparencies)

   parallel quicksort

   parallel matrix multiplication
      using co -- trace execution order
      using processes -- trace execution order; describe final code


Assign First Program

   look at it and get started with a sequential program
   look at examples online for ideas and for how to do file I/O
   come with questions on Tuesday
      we will see how to parallelize the program then


SR Execution and Implementation

   source    foo.sr
   compile   sr foo.sr
   linker    srl resource_name  (usually automatic)
             srl -l   run-time limits
   execute   a.out arguments

   multiSR   set SR_PARALLEL environment variable (default value = 1)

   Interface directory  created automatically

   each SR process executes as a thread
   SR run time system (RTS) uses spawn (fork) to start them and wait (join)
      to wait for them to finish

   the RTS provides concurrency features, I/O, and other functions

   see Appendix C of SR book for functions, Appendix D for execution,
   and Appendix E for implementation