Skip to Main Content
Mathematica 錦囊妙計
book

Mathematica 錦囊妙計

by Sal Mangano
April 2014
Beginner to intermediate content levelBeginner to intermediate
830 pages
15h 21m
Chinese
GoTop Information, Inc.
Content preview from Mathematica 錦囊妙計
16.10 運算核心間共享資料
|
659
16.10 運算核心間共享資料
問題點
你的平行運算實作需要在各運算核心之間經由共享變數互相溝通。
解決方案
Mathematica 提供
SetSharedVariable
指令可在各運算核心之間同步變數定義;同樣地,
SetSharedFunction
指令則可同步符號的 downvalue。以下範例中,
list
變數是各運算
核心共享的,且每一核心都可以加入其
$KernelID
值。
討論說明
假設你正在解組合最佳化的問題,如旅行推銷員問題(traveling salesperson problem
TSP),可能會希望每個核心都可知道目前最佳解,以避免重複計算。以下是 TSP 問題
的一種解法,使用的是模擬退火演算法。[Page-663]
16.11  於多核心運行時避免競態條件
Race Condition
問題點
Mathematica 7 版之前,使用者不必擔心競態條件等問題,因為所有的處理程序都
在單一執行緒下進行;在進入平行處理的領域後,由於各核心均會存取共享檔案及變
數,而導致某些微妙錯誤可能出現,除非經過特別處理,否則共享資源的同步性容易發
生問題。
ch16.indd 659 2014/4/2 下午 04:11:10
660
|
第十六章
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ubuntu for Non-Geeks, 4th Edition

Ubuntu for Non-Geeks, 4th Edition

Rickford Grant, Phil Bull

Publisher Resources

ISBN: 9789863470106