COMSOL-并行計(jì)算

參考blog:https://www.comsol.com/blogs/added-value-task-parallelism-batch-sweeps/

我們知道并行計(jì)算可以加快計(jì)算速度,但是這個(gè)加快不是無限制的场航,而且這個(gè)速度的加快程度依賴于我們的algorithm的具體寫法。在本文中我們從理論山解釋了parallel comuting的limitations纽甘。同時(shí)展示了怎么借用comsol的batch sweep來improving performance when you reach these limits.

Amdahl’s and Gustafson-Barsis’ laws

算法分為serial algorithm和parallel algorithm亥鬓。通過增加計(jì)算單元(也叫作process或者threads),可以加快paralle algorithm的速度,但是對(duì)于serial algorithm 無效拢肆。我們實(shí)際中寫的algorithm大約是兩種algorithm的一種混合。假定代碼中parallel code 占比為\varphi,則serial algorithm為(1-\varphi)靖诗」郑考慮計(jì)算時(shí)間T(P),P代表進(jìn)程(Process)數(shù)目呻畸。當(dāng)P=1時(shí)移盆,計(jì)算時(shí)間記做T(1),那么當(dāng)active process 為P時(shí),計(jì)算時(shí)間為:T(P)=T(1) \cdot(\varphi / P+(1-\varphi))伤为,那么相應(yīng)的speedup為:S(P):=T(1) / T(P)=1 /(\varphi / P+(1-\varphi))

Amdahl’s Law

For 100% parallelized code, the sky is the limit. 當(dāng)\varphi<1咒循,speedup會(huì)有一個(gè)limit:
S_{\max }(\varphi):=\lim _{P \rightarrow \infty} S(P)=1 /(1-\varphi)。比如如下圖所示:S_{\max }(0.5)=2

The speedup for increasing the number of processes for different fractions of parallelizable code

Gustafson-Barsis’ Law

Amdahl’s law assumes that the size of the problem is fixed. Yet, by assuming that the size of the problem increases with the number of added processes, then you are utilizing all the processes to an assumed level, and the speedup of the performed computations remains unbounded.

When taking into account that the size of the job normally increases with the number of available processes, our predictions are more optimistic.

The Cost of Communication

Gustafson-Barsis’ law implies that we are only restricted in the size of the problem we can compute绞愚,but sometimes communication is expensive. Let’s consider an overhead that is dominated by the communication and synchronization required in parallel processing, and model this as time added to the computation time.

In the case of no overhead, the result is as predicted by Amdahl’s law(last picture), but when we start adding overhead, we see that something is happening.

Speedup with added overhead. The constant, c, is chosen to be 0.005. Different line represents the different function that describes the communication

For a quadratic function, the result is worse and, as you might recall from our earlier blog post on distributed memory computing, the increase of communication is quadratic in the case of all-to-all communication. Due to this phenomenon, we cannot expect to have a speedup on a cluster for, say, a small time-dependent problem when adding more and more processes. The amount of communication would increase faster than any gain from added processes. 不過我們此時(shí)考慮的是fixed size的problem叙甸,事實(shí)上,當(dāng)我們?cè)龃髉roblem的size的時(shí)候位衩, “slowdown” effect introduced through communication would be less relevant裆蒸。

Batch Sweeps in COMSOL Multiphysics

As our example model, we will use the electrodeless lamp, which is available in the Model Gallery. This model is small, at around 80,000 degrees of freedom, but needs about 130 time steps in its solution. To make this transient model parametric as well, we will compute the model for several values of the lamp power, namely 50 W, 60 W, 70 W, and 80 W.
On my workstation, a Fujitsu? CELSIUS? equipped with an Intel? Xeon? E5-2643 quad core processor and 16 GB of RAM, the following compute times are received:

Number of Cores Compute Time per Parameter Compute Time for Sweep
1 30 mins 120 mins
2 21 mins 82 mins
3 17 mins 68 mins
4 18 mins 72 mins

從上表可以看出,只是增加電腦利用的核數(shù)并不能增加速度糖驴,反而當(dāng)有3核改為4核之后速度變慢了僚祷。

We will now use the batch sweep functionality to parallelize this problem in another way: we will switch from data parallelism to task parallelism. We will create a batch job for each parameter value and see what this does to our computation times.

Simulations per day for the electrodeless lamp model. “4×1” means four batch jobs run simultaneously, using one core each.

從上圖可以看出佛致,當(dāng)我們把工作分成同時(shí)工作的四份,每份工作占用一個(gè)核辙谜,速度可以大大加快俺榆。


在我在自己的電腦上測(cè)試squareloop的工作的時(shí)候發(fā)現(xiàn)建立batch sweep確實(shí)也可以加快速度,我的電腦是4core装哆,16G of RAM. 1 \times 1所用時(shí)間是3min41s, 2 \times 2所用時(shí)間是2min20s罐脊,4 \times1 所用時(shí)間是2min6s。加速效果并不是很明顯

Conclusion

在comsol中設(shè)置并行計(jì)算是個(gè)很復(fù)雜的問題蜕琴,就像怎么選擇求解器一樣萍桌。和要解決的問題,以及計(jì)算機(jī)的性能特點(diǎn)都很有關(guān)系凌简。

Selecting the right parallel configuration is not always easy, and it can be hard to know beforehand how you should “hybridize” your parallel computations. But as in many other cases, experience comes from playing around and testing, and with COMSOL Multiphysics, you have the possibility to do that. Try it yourself with different configurations and different models, and you will soon know how to set the software up in order to get the best performance out of your hardware.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末上炎,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子号醉,更是在濱河造成了極大的恐慌反症,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,907評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件畔派,死亡現(xiàn)場(chǎng)離奇詭異铅碍,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)线椰,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,987評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門胞谈,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人憨愉,你說我怎么就攤上這事烦绳。” “怎么了配紫?”我有些...
    開封第一講書人閱讀 164,298評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵径密,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我躺孝,道長(zhǎng)享扔,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,586評(píng)論 1 293
  • 正文 為了忘掉前任植袍,我火速辦了婚禮惧眠,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘于个。我一直安慰自己氛魁,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,633評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著秀存,像睡著了一般捶码。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上或链,一...
    開封第一講書人閱讀 51,488評(píng)論 1 302
  • 那天宙项,我揣著相機(jī)與錄音,去河邊找鬼株扛。 笑死,一個(gè)胖子當(dāng)著我的面吹牛汇荐,可吹牛的內(nèi)容都是我干的洞就。 我是一名探鬼主播,決...
    沈念sama閱讀 40,275評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼掀淘,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼旬蟋!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起革娄,我...
    開封第一講書人閱讀 39,176評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤倾贰,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后拦惋,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體匆浙,經(jīng)...
    沈念sama閱讀 45,619評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,819評(píng)論 3 336
  • 正文 我和宋清朗相戀三年厕妖,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了首尼。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,932評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡言秸,死狀恐怖软能,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情举畸,我是刑警寧澤查排,帶...
    沈念sama閱讀 35,655評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站抄沮,受9級(jí)特大地震影響跋核,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜合是,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,265評(píng)論 3 329
  • 文/蒙蒙 一了罪、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧聪全,春花似錦泊藕、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,871評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽玫锋。三九已至,卻和暖如春讼呢,著一層夾襖步出監(jiān)牢的瞬間撩鹿,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,994評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工悦屏, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留节沦,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,095評(píng)論 3 370
  • 正文 我出身青樓础爬,卻偏偏與公主長(zhǎng)得像甫贯,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子看蚜,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,884評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • 期中考試已經(jīng)告一段落了叫搁,對(duì)于本次的期中考試,我最關(guān)心的事莫過于各科的成績(jī)了供炎。成績(jī)很不理想渴逻。其實(shí)分?jǐn)?shù)只不過是檢...
    21980e55a4dd閱讀 241評(píng)論 0 0
  • Translate form http://www.raywenderlich.com/84434/sprite-...
    CenturyGuo閱讀 2,188評(píng)論 1 11
  • 去年澇,麥種不成音诫; 今年旱惨奕,麥種不上。 據(jù)說出了旱枯樁纽竣,咱請(qǐng)白龍來幫忙墓贿。 人停機(jī)不停,奮戰(zhàn)到天明蜓氨。 三農(nóng)要振興聋袋,水...
    花癡_halou閱讀 141評(píng)論 0 3