Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 public class UnboundedDEQueue { 2 3 4 5 6 7 private final static int LOG_CAPACITY = 4; private volatile CircularArray tasks; volatile int

image text in transcribedimage text in transcribedimage text in transcribed

1 public class UnboundedDEQueue { 2 3 4 5 6 7 private final static int LOG_CAPACITY = 4; private volatile CircularArray tasks; volatile int bottom; AtomicReference top;; public UnboundedDEQueue (int LOG_CAPACITY) { tasks new CircularArray (LOG_CAPACITY); top = new AtomicReference (0); bottom = 0; boolean isEmpty() { int local Top top.get(); int localBottom bottom; return (localBottom P(x) Q(x) = (P(x) Qo(x)) + (Po(x) Q(x) + P(x) Qo(x)) x/ + (P(x) Q(x)) 1 public class MatrixTask { 12345698 7 static ExecutorService exec Executors.newCachedThreadPool(); static Matrix add (Matrix a, Matrix b) throws ExecutionException { int na.getDim(); Matrix c new Matrix(n); Future future = exec.submit(new AddTask(a, b, c)); future.get(); return c; static class AddTask implements Runnable { Matrix a, b, c; public AddTask(Matrix myA, Matrix myB, Matrix myC) { 9 10 } 11 12 13 14 15 } 16 17 18 19 20 21 } 37 } 34 35 36 22222222222222222mmm a = myA; b = myB; c = myC; public void run() { try { int n a.getDim(); 23 28 29 30 31 32 33 if (n = 1) { c.set(0, 0, a.get(0,0) + b.get(0,0)); } else { Matrix aaa.split(), bbb.split(), cc = c.split(); Future future (Future [][]) new Future[2] [2]; for (int i=0; i < 2; 1++) for (int j=0; j < 2; j++) future[1][j] = exec.submit(new AddTask(aa[i][j], bb[i][j], cc[i][j])); for (int 0; i < 2; i++) for (int j=0; j < 2; j++) future[i][j].get(); } catch (Exception ex) { ex.printStackTrace(); Figure 16.4 The MatrixTask class: parallel matrix addition.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions