COMSOL-并行计算

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

我们知道并行计算可以加快计算速度,但是这个加快不是无限制的,而且这个速度的加快程度依赖于我们的algorithm的具体写法。在本文中我们从理论山解释了parallel comuting的limitations。同时展示了怎么借用comsol的batch sweep来improving performance when you reach these limits.

Amdahl’s and Gustafson-Barsis’ laws

算法分为serial algorithm和parallel algorithm。通过增加计算单元(也叫作process或者threads),可以加快paralle algorithm的速度,但是对于serial algorithm 无效。我们实际中写的algorithm大约是两种algorithm的一种混合。假定代码中parallel code 占比为\varphi,则serial algorithm为(1-\varphi)。考虑计算时间T(P),P代表进程(Process)数目。当P=1时,计算时间记做T(1),那么当active process 为P时,计算时间为:T(P)=T(1) \cdot(\varphi / P+(1-\varphi)),那么相应的speedup为:S(P):=T(1) / T(P)=1 /(\varphi / P+(1-\varphi))

Amdahl’s Law

For 100% parallelized code, the sky is the limit. 当\varphi<1,speedup会有一个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. 不过我们此时考虑的是fixed size的problem,事实上,当我们增大problem的size的时候, “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

从上表可以看出,只是增加电脑利用的核数并不能增加速度,反而当有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.

从上图可以看出,当我们把工作分成同时工作的四份,每份工作占用一个核,速度可以大大加快。


在我在自己的电脑上测试squareloop的工作的时候发现建立batch sweep确实也可以加快速度,我的电脑是4core,16G of RAM. 1 \times 1所用时间是3min41s, 2 \times 2所用时间是2min20s,4 \times1 所用时间是2min6s。加速效果并不是很明显

Conclusion

在comsol中设置并行计算是个很复杂的问题,就像怎么选择求解器一样。和要解决的问题,以及计算机的性能特点都很有关系。

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.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 215,245评论 6 497
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,749评论 3 391
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 160,960评论 0 350
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,575评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,668评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,670评论 1 294
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,664评论 3 415
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,422评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,864评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,178评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,340评论 1 344
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,015评论 5 340
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,646评论 3 323
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,265评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,494评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,261评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,206评论 2 352

推荐阅读更多精彩内容

  • 期中考试已经告一段落了,对于本次的期中考试,我最关心的事莫过于各科的成绩了。成绩很不理想。其实分数只不过是检...
    21980e55a4dd阅读 241评论 0 0
  • Translate form http://www.raywenderlich.com/84434/sprite-...
    CenturyGuo阅读 2,187评论 1 11
  • 去年涝,麦种不成; 今年旱,麦种不上。 据说出了旱枯桩,咱请白龙来帮忙。 人停机不停,奋战到天明。 三农要振兴,水...
    花痴_halou阅读 139评论 0 3