Dana Vrajitoru
B424 Parallel and Distributed Programming

Exploratory and Speculative Decomposition

Exploratory Decomposition

Figure: Tic Tac Toe game, exploratory decomposition

Speculative Decomposition

Sequential version Parallel version
compute expr;
switch (expr) {
  case 1:
    compute a1;     
    break;
  case 2:
    compute a2;
    break;
  case 3:
    compute a3;
    break;...
}

Slave(i) 
{
  compute ai;
  Wait(request);
  if (request) 
    Send(ai, 0); 
}
Master() 
{
  compute expr;
  swicth (expr) {
    case 1: 
      Send(request, 1);      
      Receive(a1, i); 
  ...
}

Example - TTT Game

Figure: Tic Tac Toe game, speculative decomposition

Discreet Event Simulation


Figure: Discreet event simulation


Topological Sorting

The Problem

A graph with no solution because of the cycle 5 6 9 5.    A modification of the graph that makes the topological sorting possible.

Sequential Version

boolean topologically_number (digraph G)
{
  for (ever vertex v in G) {
    visited[v] = false;
    numbered[v] = false;
  }
  int topol_counter = number_of_vertices(G);
  for (each vertex v in G)
    if (!visited[v]) {
      visited[v] = true;
      if (!recursively_number(G, v, topol_counter))
        return false;
    }
  return true;
}

boolean recursively_number (digraph G, int v, int & counter)
{
  for (each w that can be reached from v) {
    if (numbered[w]);
    else if (visited[w]) // but not numbered
      return false;  // a cycle has been found
    else {
      visited[w] = true;
      if (!recursively_number (G, w, counter))
        return false; 
    }
  }     
  vertex[v].topol_number = counter; 
  -- counter;
  return true; // no cycles were detected
}

Parallel Outline

Process(id) 
{
  for all incoming "in"
    Receive(dummy, in);
  output id;
  Perform_task(id);
  for all outgoing "out"
    Send(dummy, out);
}

Critical Path