High performance java platform computing multithreaded and networked programming

421 48 0
High performance java platform computing  multithreaded and networked programming

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

High-Performance Platform Computing THOMAS W CHRISTOPHER • GEORGE K THIRUVATHUKAL Copyright (c) 2000 by Thomas W Christopher and George K Thiruvathukal Permission is granted to make copies, provided the copyright notice remains intact and the Prentice Hall PTR, Upper Saddle River, NJ 07458 Sun Microsystems Press integrity of the text is preserved www.phptr.com A Prentice Hall Title This work was previously published by Pearson Education, Inc Preface, xv Acknowledgments, xxi Chapter Foundations, The von Neumann Machine, Flynn’s Taxonomy, Control–Memory Taxonomy, Speedup and Efficiency, Amdahl’s Law, Scalability, Problems of Parallelism, 10 Grain Size, 10 Starvation, 11 Deadlock, 11 v vi High-Performance Java Platform Computing Flooding and Throttling, 11 Layout, 12 Latency, 13 Scheduling, 13 Programming Techniques, 15 Chapter Wrap-up, 15 Exercises, 16 Chapter Threads, 19 Why is Multithreading Useful? 20 Overview of the Java Threads Classes, 21 Thread: The Class Responsible for Thread Creation and Execution, 21 Runnable: Making Threads Without Extending the Thread Class, 23 Hello World: A First Example of Multithreading, 25 Implementing Interfaces and Extending Classes: What’s the Deal? 27 Concepts, 28 A Little Bit of History, 29 Some Definitions, 30 Multiprogramming vs Multitasking, 31 Concurrency vs Parallelism vs Distribution, 32 Threads vs Processes, 33 Kernel-level vs User-level Threads, 36 Quick Tour of Java Threads Functions, 37 Construction, 37 Daemon Threads, 38 Thread Control, 38 Very Useful Static Methods, 39 Thread Synchronization, 39 Cooperative Multitasking, 40 Prioritized Scheduling, 40 Contents Miscellaneous Status Methods, 41 Methods Not Covered Here, 41 Exercises, 41 Chapter Race Conditions and Mutual Exclusion, 43 Know Your Enemy! 44 Race Conditions, 44 Egoist: A First Study in Race Conditions, 44 A Word on Priorities, 46 What is a Race Condition? 47 Race0 Class, 48 Critical Sections and Object Locking, 52 Race1 Class—Fixing Race0 with Synchronization, 53 Conditions, 55 Motivating the Need for Conditions, 55 Key Object Methods Needed to Work with Conditions in Java, 57 File Copying: A Producer–Consumer Example, 58 Locks–Binary Semaphores: An Example of Using Conditions, 68 Race2: Reworked Race1 Using Locks, 71 Classic Synchronization Mechanisms, 73 Counting Semaphore, 73 Barrier, 75 Futures, 76 Deadlock, 78 What is Deadlock? 78 How to Know When Deadlock Has Hit You? 78 Four Conditions of Deadlock, 78 A Classic Example: Dining Philosophers, 79 Chapter Wrap-up, 85 Exercises, 87 vii viii High-Performance Java Platform Computing Chapter Monitors, 89 Real Monitors and Java Monitors, 89 Class Monitor in the Thread Package, 92 Monitor’s Methods, 94 Interface MonitorCondition’s Methods, 95 Interface MonitorLock, 96 Examples using Monitor Objects, 97 SimpleFuture, 97 SharedTableOfQueues, 98 Implementation of Monitor, Condition, and MonitorLock, 101 Monitor Entry and Exit, 102 Monitor.Condition, 105 Monitor.Lock, 109 The Multiple Reader–Writer Monitors, 110 Policies, 111 Entering and Leaving the Critical Sections, 112 The Single-Reader–Writer Monitor, 112 The Readers-Preferred Monitor, 113 The Writers-Preferred Monitor, 115 The Alternating Readers–Writers Monitor, 117 The Take-a-Number Monitor, 119 Chapter Wrap-up, 120 Exercises, 121 Chapter Parallel Execution of Subroutines in Shared Memory, 123 Creating and Joining, 124 Contents Example: Trapezoidal Numeric Integration, 125 RunQueue, 129 RunQueue Methods, 129 RunQueue Implementation, 133 Recursive Shell Sort: RunQueues and SimpleFutures, 138 Accumulator, 141 Accumulator Operations, 141 Patterns of Use of Accumulators, 142 Using Accumulators, 144 Numeric Integration, 144 TerminationGroup, 147 Combinatorial Search, 149 The 0–1 Knapsack Problem, 149 Parallel Depth-first Search for the Knapsack Problem, 152 Knapsack2, 154 PriorityRunQueue, 159 Branch-and-Bound with Priority Run Queues, 161 Branch and Bound for 0–1 Knapsack, 161 A Purer Branch-and-Bound 0–1 Knapsack, 167 Chapter Wrap-up, 167 Exercises, 170 Chapter Parallelizing Loops, 171 Chore Graphs, 172 Gathering Chores into Threads, 174 Example: Warshall’s Algorithm, 174 Static Scheduling, 177 Dynamic Scheduling, 177 Example: Longest Common Subsequence, 184 ix x High-Performance Java Platform Computing Example: Shell Sort, 189 Chapter Wrap-up, 194 Exercises, 195 Chapter Chores, 197 The RunDelayed Interface, 199 Futures, 199 FutureFactory, 201 Chore-programming Techniques, 201 Job Jars, 202 Chore Graphs, 202 Macro Dataflow, 202 Flow of Control, 206 Macro Dataflow Examples: Vector Addition, 209 Continuations to Separate Operand Fetch from Operation, 210 Static Dataflow Style and Storing Operands in Instructions, 213 Fetching in Continuations, 217 Chore examples: Warshall’s Algorithm, 218 WarshallDF1 and Warshall’s Algorithm in Dataflow, 219 WarshallC1 through WarshallC3: Chores, But Not Dataflow, 223 Chapter Wrap-up, 236 Exercises, 237 Chapter Thread and Chore Synchronization, 239 TerminationGroup, 239 Barrier, 241 Contents BarrierFactory, 243 AccumulatorFactory, 244 Parallel Quicksort, 244 Shell Sort, 248 Chapter Wrap-up, 256 Chapter Shared Tables of Queues, 257 Shared Tables of Queues, 258 Methods, 258 Implementing Synchronizations Using a Shared Table of Queues, 260 Indexed Keys, 262 Implementing More Synchronizations and Shared Structures, 265 Reactive Objects, 268 Communicating through a Shared Table of Queues, 271 Future Queues, 277 Methods, 278 Implementation of FutureQueue, 280 Example of FutureQueue: The Queued Readers–Writers Monitor, 285 Future Tables, 287 Chapter Wrap-up, 287 Exercises, 288 Chapter 10 Streams Essentials, 289 The Streams Abstraction, 290 Building Your Own Stream, 291 xi xii High-Performance Java Platform Computing Caesar Cipher: Very Basic Encryption, 299 Chapter Wrap-up, 287 Exercises, 288 Chapter 11 Networking, 307 Exploring the Client Side, 308 Services: The Internet Story, 310 Destination Sendmail, 312 Java Networking: Socket and InetAddress, 315 Where Are the Services? 325 A Kind and Gentle Introduction to the Server Side, 334 Iterative Servers, 335 Simple Messaging Architecture, 341 The Message Class, 342 DateService and DateClient SMA Style, 355 Chapter Wrap-Up, 358 Exercises, 358 Chapter 12 Coordination, 361 Generic Mailbox Invocations, 362 GMI: Goals and Design Overview, 363 Callable: An Interface for Accepting Communication, 363 CallMessage: An Abstract Class for Marshalling and Unmarshalling! 364 RemoteCallServer, 365 RemoteCallServerDispatcher, 367 RemoteCallClient, 369 Contents Memo: A Remote Interface to SharedTableOfQueues, 372 Design, 372 MemoServer, 376 MemoClient, 377 Vector Inner Product, 379 Trapezoidal Integration, 386 Warshall’s Algorithm, 391 Chapter Wrap-up, 398 Exercises, 398 Index, 401 xiii coordination.fm Page 396 Thursday, July 13, 2000 10:40 PM 396 High-Performance Java Platform Computing public void closureMergeResults(boolean[][] a) throws Exception { for (int i=0; i < numBlocks; i++) { Block result = (Block) space.get(“blockClosure”); result.merge(a); } } That’s it It is just a matter of getting the blockClosure result that was written by the closureDoWork() method and then telling the object to replace its part of the boolean matrix (a) with its submatrix In the foregoing discussion, we made unresolved “forward” references to two aspects of the Block class, which exists for the sole purpose of holding part of the boolean matrix (a submatrix) and performing the closure The actual work of the closure is done in the run() method, which is shown next (the Block class is virtually unchanged from the original code, except that it now appears as a separate, unnested class): public void run(){ int i,j; int k; boolean IHaveRow,IHaveColumn; boolean[] row=null, col=null; try { for (k=0;k=0 && k-r < nr; IHaveColumn = k-c>=0 && k-c < nc; if (IHaveRow) { BooleanArray myRow; myRow = new BooleanArray(block[k-r]); space.put(rows.at(k+c*N), myRow); row = block[k-r]; } if (IHaveColumn) { col=new boolean[nr]; for (j=0;j

Ngày đăng: 04/03/2019, 08:54

Mục lục

  • Chapter 1: Foundations

    • The von Neumann Machine

    • Problems of Parallelism

      • Grain Size

      • Chapter 2: Threads

        • Why is Multithreading Useful?

        • Overview of the Java Threads Classes

          • Thread: The Class Responsible for Thread Creation and Execution

          • Runnable: Making Threads Without Extending the Thread Class

          • Hello World: A First Example of Multithreading

          • Implementing Interfaces and Extending Classes: What’s the Deal?

          • Concepts

            • A Little Bit of History

            • Multiprogramming vs. Multitasking

              • Java Support for Multiprogramming

              • Quick Tour of Java Threads Functions

                • Construction

                • Very Useful Static Methods

                • Methods Not Covered Here

                • Chapter 3: Race Conditions and Mutual Exclusion

                  • Know Your Enemy!

                  • Race Conditions

                    • Egoist: A First Study in Race Conditions

                    • A Word on Priorities

                    • What is a Race Condition?

                    • Critical Sections and Object Locking

                    • Race1 Class—Fixing Race0 with Synchronization

                    • Conditions

                      • Motivating the Need for Conditions

                      • Key Object Methods Needed to Work with Conditions in Java

Tài liệu cùng người dùng

Tài liệu liên quan