具体描述
并行编程已不仅仅是面向专业技术人员的一门学科。如果想要全面开发机群和多核处理器的计算能力,那么学习分布式内存和共享式内存的并行编程技术是不可或缺的。本书循序渐进地展示了如何利用MPI、PThread 和OpenMP开发高效的并行程序,教给读者如何开发、调试分布式内存和共享式内存的程序,以及对程序进行性能评估。
本书特色
· 采用教程形式,从简短的编程实例起步,一步步编写更有挑战性的程序。
· 重点介绍分布式内存和共享式内存的程序设计、调试和性能评估。
· 使用MPI、PThread 和OpenMP等编程模型,强调实际动手开发并行程序。
【编辑推荐】
毫无疑问,随着多核处理器和云计算系统的广泛应用,并行计算不再是计算世界中被束之高阁的偏门领域。并行性已经成为有效利用资源的首要因素,Peter Pacheco撰写的这本新教材对于初学者了解并行计算的艺术和实践很有帮助。
——Duncan Buell,南卡罗来纳大学计算机科学与工程系
本书阐述了两个越来越重要的领域:使用Pthread和OpenMP进行共享式内存编程,以及使用MPI进行分布式内存编程。更重要的是,它通过指出可能出现的性能错误,强调好的编程实现的重要性。这本书在不同学科(包括计算机科学、物理和数学等)背景下介绍以上话题。各章节包含了难易程度不同的编程习题。对于希望学习并行编程技巧、扩展知识面的学生或专业人士来说,这是一本理想的参考书籍。
——Leigh Little,纽约州立大学布罗科波特学院计算机科学系
本书是一本精心撰写的全面介绍并行计算的书籍。学生以及相关领域从业者会从书中的相关最新信息中获益匪浅。作者以通俗易懂的写作手法,结合各种有趣的实例使本书引人入胜。在并行计算这个瞬息万变、不断发展的领域里,本书深入浅出、全面涵盖了并行软件和硬件的方方面面。
——Kathy J. Liszka,阿克隆大学计算机科学系
作者简介
Peter Pacheco 拥有佛罗里达州立大学数学专业博士学位。曾担任旧金山大学计算机系主任,目前是旧金山大学数学系主任。近20年来,一直为本科和研究生讲授并行计算课程。
目录信息
1.1 why we need ever-increasing performance 2
1.2 why we’re building parallel systems 3
1.3 why we need to write parallel programs 3
1.4 how do we write parallel programs? 6
1.5 what we’ll be doing 8
1.6 concurrent, parallel, distributed 9
1.7 the rest of the book 10
1.8 a word of warning 10
1.9 typographical conventions 11
1.10 summary 12
1.11 exercises 12
chapter 2 parallel hardware and parallel software 15
2.1 some background15
2.1.1 the von neumann architecture 15
2.1.2 processes, multitasking, and threads 17
2.2 modifications to the von neumann model 18
2.2.1 the basics of caching 19
2.2.2 cache mappings 20
.2.2.3 caches and programs: an example 22
2.2.4 virtual memory 23
2.2.5 instruction-level parallelism 25
2.2.6 hardware multithreading 28
2.3 parallel hardware 29
2.3.1 simd systems 29
2.3.2 mimd systems 32
2.3.3 interconnection networks 35
2.3.4 cache coherence 43
2.3.5 shared-memory versus distributed-memory 46
2.4 parallel software 47
2.4.1 caveats 47
2.4.2 coordinating the processes/threads 48
2.4.3 shared-memory 49
2.4.4 distributed-memory 53
2.4.5 programming hybrid systems 56
2.5 input and output 56
2.6 performance 58
2.6.1 speedup and efficiency 58
2.6.2 amdahl’s law 61
2.6.3 scalability 62
2.6.4 taking timings 63
2.7 parallel program design 65
2.7.1 an example 66
2.8 writing and running parallel programs 70
2.9 assumptions 70
2.10 summary 71
2.10.1 serial systems 71
2.10.2 parallel hardware 73
2.10.3 parallel software 74
2.10.4 input and output 75
2.10.5 performance 75
2.10.6 parallel program design 76
2.10.7 assumptions 76
2.11 exercises 77
chapter 3 distributed-memory programming with mpi 83
3.1 getting started84
3.1.1 compilation and execution 84
3.1.2 mpi programs 86
3.1.3 mpi init and mpi finalize 86
3.1.4 communicators, mpi comm size and mpi comm rank 87
3.1.5 spmd programs 88
3.1.6 communication 88
3.1.7 mpi send 88
3.1.8 mpi recv 90
3.1.9 message matching 91
3.1.10 the status p argument 92
3.1.11 semantics of mpi send and mpi recv 93
3.1.12 some potential pitfalls 94
3.2 the trapezoidal rule in mpi 94
3.2.1 the trapezoidal rule 94
3.2.2 parallelizing the trapezoidal rule 96
contents xiii
3.3 dealing with i/o 97
3.3.1 output 97
3.3.2 input 100
3.4 collective communication101
3.4.1 tree-structured communication 102
3.4.2 mpi reduce 103
3.4.3 collective vspoint-to-point communications 105
3.4.4 mpi allreduce 106
3.4.5 broadcast 106
3.4.6 data distributions 109
3.4.7 scatter 110
3.4.8 gather 112
3.4.9 allgather 113
3.5 mpi derived datatypes 116
3.6 performance evaluation of mpi programs119
3.6.1 taking timings 119
3.6.2 results 122
3.6.3 speedup and efficiency 125
3.6.4 scalability 126
3.7 a parallel sorting algorithm 127
3.7.1 some simple serial sorting algorithms 127
3.7.2 parallel odd-even transposition sort 129
3.7.3 safety in mpi programs 132
3.7.4 final details of parallel odd-even sort 134
3.8 summary 136
3.9 exercises 140
3.10 programming assignments 147
chapter 4 shared-memory programming with pthreads 151
4.1 processes, threads, and pthreads 151
4.2 hello, world 153
4.2.1 execution 153
4.2.2 preliminaries 155
4.2.3 starting the threads 156
4.2.4 running the threads 157
4.2.5 stopping the threads 158
4.2.6 error checking 158
4.2.7 other approaches to thread startup159
4.3 matrix-vector multiplication 159
4.4 critical sections 162
xiv contents
4.5 busy-waiting 165
4.6 mutexes 168
4.7 producer-consumer synchronization and semaphores171
4.8 barriers and condition variables 176
4.8.1 busy-waiting and a mutex 177
4.8.2 semaphores 177
4.8.3 condition variables 179
4.8.4 pthreads barriers 181
4.9 read-write locks 181
4.9.1 linked list functions 181
4.9.2 a multi-threaded linked list 183
4.9.3 pthreads read-write locks 187
4.9.4 performance of the various implementations 188
4.9.5 implementing read-write locks 190
4.10 caches, cache coherence, and false sharing 190
4.11 thread-safety 195
4.11.1 incorrect programs can produce correct output 198
4.12 summary 198
4.13 exercises 200
4.14 programming assignments 206
chapter 5 shared-memory programming with openmp 209
5.1 getting started210
5.1.1 compiling and running openmp programs 211
5.1.2 the program 212
5.1.3 error checking 215
5.2 the trapezoidal rule 216
5.2.1 a first openmp version 216
5.3 scope of variables 220
5.4 the reduction clause 221
5.5 the parallel for directive 224
5.5.1 caveats 225
5.5.2 data dependences 227
5.5.3 finding loop-carried dependences 228
5.5.4 estimating 229
5.5.5 more on scope 231
5.6 more about loops in openmp: sorting 232
5.6.1 bubble sort 232
5.6.2 odd-even transposition sort 233
5.7 scheduling loops 236
5.7.1 the schedule clause 237
5.7.3 the dynamic and guided schedule types 239
5.7.4 the runtime schedule type 239
5.7.5 which schedule? 241
5.8 producers and consumers 241
5.8.1 queues 241
5.8.2 message-passing 242
5.8.3 sending messages 243
5.8.4 receiving messages 243
5.8.5 termination detection 244
5.8.6 startup 244
5.8.7 the atomic directive 245
5.8.8 critical sections and locks 246
5.8.9 using locks in the message-passing program 248
5.8.10 critical directives, atomic directives,
or locks? 249
5.8.11 some caveats 249
5.9 caches, cache coherence, and false sharing 251
5.10 thread-safety 256
5.10.1 incorrect programs can produce correct output 258
5.11 summary 259
5.12 exercises 263
5.13 programming assignments 267
chapter 6 parallel program development 271
6.1 two n-body solvers 271
6.1.1 the problem 271
6.1.2 two serial programs 273
6.1.3 parallelizing the n-body solvers 277
6.1.4 a word about i/o 280
6.1.5 parallelizing the basic solver using openmp 281
6.1.6 parallelizing the reduced solver using openmp 284
6.1.7 evaluating the openmp codes 288
6.1.8 parallelizing the solvers using pthreads 289
6.1.9 parallelizing the basic solver using mpi 290
6.1.10 parallelizing the reduced solver using mpi 292
6.1.11 performance of the mpi solvers 297
6.2 tree search 299
6.2.1 recursive depth-first search 302
6.2.2 nonrecursive depth-first search 303
6.2.3 data structures for the serial implementations 305
6.2.6 a static parallelization of tree search using pthreads 309
6.2.7 a dynamic parallelization of tree search using pthreads 310
6.2.8 evaluating the pthreads tree-search programs 315
6.2.9 parallelizing the tree-search programs using openmp 316
6.2.10 performance of the openmp implementations 318
6.2.11 implementation of tree search using mpi and static partitioning 319
6.2.12 implementation of tree search using mpi and dynamic partitioning 327
6.3 a word of caution 335
6.4 which api? 335
6.5 summary 336
6.5.1 pthreads and openmp 337
6.5.2 mpi 338
6.6 exercises 341
6.7 programming assignments 350
chapter 7 where to go from here 353
references 357
index 361
· · · · · · (收起)
读后感
首先,本书前两章,主要介绍了并行编程的一些基本知识,包括并行编程的重要性,并行硬件的几种方式以及并行软件的几种范式。其中并行硬件的几种方式包括,1,SIMD,单指令多数据流;2,MIMD,多指令多数据流。并行软件,实践中主要采用的是SPMD方式,即单程序多数据流方式。优...
首先,本书前两章,主要介绍了并行编程的一些基本知识,包括并行编程的重要性,并行硬件的几种方式以及并行软件的几种范式。其中并行硬件的几种方式包括,1,SIMD,单指令多数据流;2,MIMD,多指令多数据流。并行软件,实践中主要采用的是SPMD方式,即单程序多数据流方式。优...
首先,本书前两章,主要介绍了并行编程的一些基本知识,包括并行编程的重要性,并行硬件的几种方式以及并行软件的几种范式。其中并行硬件的几种方式包括,1,SIMD,单指令多数据流;2,MIMD,多指令多数据流。并行软件,实践中主要采用的是SPMD方式,即单程序多数据流方式。优...
首先,本书前两章,主要介绍了并行编程的一些基本知识,包括并行编程的重要性,并行硬件的几种方式以及并行软件的几种范式。其中并行硬件的几种方式包括,1,SIMD,单指令多数据流;2,MIMD,多指令多数据流。并行软件,实践中主要采用的是SPMD方式,即单程序多数据流方式。优...
首先,本书前两章,主要介绍了并行编程的一些基本知识,包括并行编程的重要性,并行硬件的几种方式以及并行软件的几种范式。其中并行硬件的几种方式包括,1,SIMD,单指令多数据流;2,MIMD,多指令多数据流。并行软件,实践中主要采用的是SPMD方式,即单程序多数据流方式。优...
用户评价
这本书给我的感觉是,它打破了传统技术书籍的刻板印象,充满了活力和探索精神。作者的写作风格兼具学术的严谨和工程师的务实,使得这本书既有可以作为工具书随时翻阅的价值,又有可以像小说一样沉浸阅读的乐趣。我尤其喜欢它在讲解抽象模型时,会巧妙地运用生活化的比喻,使得那些原本高高在上的理论变得触手可及。它不仅关注“如何做”,更深入探讨了“为什么这样做是最好的”,这种对原理的深究,才是真正区分普通程序员和优秀工程师的关键所在。这本书真正培养的是一种解决问题的能力和系统思考的框架,而不是简单的工具使用技巧。可以说,它已经成为了我书架上被翻阅次数最多的参考资料之一,每次重温都能带来新的启发和感悟。
拿到这本书时,我原本以为它会是那种枯燥乏味的教科书,充满了公式和难以理解的抽象概念。然而,事实证明我大错特错了。作者以一种近乎讲故事的方式,将复杂的并发控制理论娓娓道来,让人沉浸其中,难以自拔。它成功地将理论的严谨性与工程实践的灵活性完美结合起来。最让我印象深刻的是,书中对于不同并行编程模型的对比分析,视角独特且深入,揭示了每种选择背后的取舍与权衡。我特别喜欢它在介绍新技术时,会追溯其历史渊源,这样不仅知其然,更能知其所以然。对于那些渴望从初级程序员跃升到架构师层面的读者来说,这本书无疑是必不可少的垫脚石。它提供了一个坚实的基础,让读者有能力去应对现代软件开发中日益增长的复杂性和性能挑战。
这本书的内容丰富得让人眼花缭乱,简直是一部关于系统构建与优化的百科全书。作者的叙述风格非常细腻,即便是最晦涩难懂的概念,也能被他用清晰、生动的语言阐释得一清二楚。我尤其欣赏其中对底层硬件架构的剖析,那部分内容让我对计算机内部的运作机制有了前所未有的理解。书中不仅仅停留在理论层面,还提供了大量经过实战检验的代码示例和设计模式,这些无疑是技术人员宝贵的财富。我花了很长时间去消化其中的知识点,尤其是关于内存一致性模型和锁的精妙处理,每一次重读都能发现新的体会。读完之后,感觉自己的编程思维都有了质的飞跃,不再满足于写出能跑的代码,而是开始追求写出高效、健壮的系统。这本书的价值,远超其作为一本技术手册的范畴,它更像是一份指引未来技术方向的路线图。
老实说,市面上关于程序设计的好书不少,但能将理论深度、工程实用性以及阅读体验做到如此极致的,屈指可数。这本书的深度足以让资深专家受益匪浅,因为它探讨的许多前沿话题和底层机制,即便是业界老兵也未必能完全掌握。我尤其赞赏作者在描述多核处理器特性时的那种鞭辟入里的洞察力,让人感觉作者本人就是这些硬件的亲手设计者。书中穿插的案例分析,并非空中楼阁式的理论推演,而是紧密结合了实际应用场景,这极大地增强了知识的可迁移性。阅读过程中,我多次停下来,对照自己正在做的项目进行思考和验证,效果显著。这本书提供的知识体系是如此的全面和自洽,它为我未来在分布式系统和大规模计算领域的发展,打下了无比坚实的基础。
这本书的排版和逻辑结构设计得非常巧妙,读起来丝毫没有感到吃力。它不是那种堆砌知识点的书,而是真正构建了一个清晰的学习路径。从最基础的并行性概念开始,逐步深入到高性能计算的深水区,每一步的过渡都自然流畅,仿佛有一位经验丰富的大师在身旁悉心指导。书中对于性能瓶颈的分析尤其到位,那些在实际工作中经常遇到的棘手问题,都能在这里找到理论上的根源和解决思路。我甚至开始重新审视我过去的一些代码设计,发现了不少可以优化的地方。这本书不仅仅是教会你如何编写并行代码,更重要的是培养你一种“并行思维”,让你在面对任何复杂系统设计时,都能本能地考虑到如何利用好资源的并行能力。对于希望系统性提升工程能力的工程师来说,这是一本不可多得的武功秘籍。
讲的挺清楚,但是有点太简单了
还是需要读《Unix环境高级编程》
讲的挺清楚,但是有点太简单了
非常简单的基础知识,也就是和并行编程打个照面。里面介绍了MPI和OpenMP以及pthread三中主流的并行程序编程接口,也就是作为行内科普,了解即可,长长见识。
讲的挺清楚,但是有点太简单了