CSC/ECE 506 Spring 2010/ch 3 yl: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 48: Line 48:


  '''for''' (i=1; i<=N; i++) {
  '''for''' (i=1; i<=N; i++) {
   '''S:''' a[i] = a[i-1] + b[i] * c[i];
   '''S:''' a[i] = a[i-1] + b[i] * c[i];}
'''}'''


   '''for''' (i=1; i<=N; i++) {
   '''for''' (i=1; i<=N; i++) {
   '''S1:''' temp[i] = b[i] * c[i];
   '''S1:''' temp[i] = b[i] * c[i];}
'''}'''
  '''for''' (i=1; i<=N; i++) {
  '''for''' (i=1; i<=N; i++) {
   '''S2''': a[i] = a[i-1] + temp[i];
   '''S2''': a[i] = a[i-1] + temp[i];}'''
'''}'''


===DOPIPE===
===DOPIPE===

Revision as of 19:40, 20 February 2010

Supplement to Chapter 3: Support for parallel-programming models. Discuss how DOACROSS, DOPIPE, DOALL, etc. are implemented in packages such as Posix threads, Intel Thread Building Blocks, OpenMP 2.0 and 3.0.

Parallel-programming models

DOALL

for    i:=2:N-1 do A(i):=[A(i-1) + A(i) + A(i+1)]/3; next i;
forall i:=2:N-1 do A(i):=[A(i-1) + A(i) + A(i+1)]/3;
for (i=2; i<=n; i+=2)
 s: a[i] = a[i-2];
for (i=3; i<=n; i+=2)
 s: a[i] = a[i-2];


switch (n) {
  case 0:
    puts("You typed zero.");
    break;
  case 1:
  case 9:
    puts("n is a perfect square.");
    break;  
  case 2:
    puts("n is an even number.");
  case 3:
  case 5:
  case 7:
    puts("n is a prime number.");
    break;
  case 4:
    puts("n is a perfect square.");
  case 6:
  case 8:
    puts("n is an even number.");
    break;
  default:
    puts("Only single-digit numbers are allowed.");
    break;
}

DOACROSS

for    i:=2:N-1 do A(i):=[A(i-1) + A(i) + A(i+1)]/3; next i;
forall i:=2:N-1 do A(i):=[A(i-1) + A(i) + A(i+1)]/3;
for (i=1; i<=N; i++) {
 S: a[i] = a[i-1] + b[i] * c[i];}
 for (i=1; i<=N; i++) {
  S1: temp[i] = b[i] * c[i];}
for (i=1; i<=N; i++) {
  S2: a[i] = a[i-1] + temp[i];}

DOPIPE

Implementation

References

  1. wikipedia: Parallel Computing