首页 > 其他分享 >小技巧003-伪并行重构流场

小技巧003-伪并行重构流场

时间:2023-03-31 17:34:45浏览次数:33  
标签:重构 20 0.0 003 wli reconstruct 流场 17412 161576

小技巧003-伪并行重构流场

OpenFOAM的reconstructPar是单核程序,对于较大的算例重构流场时间过长,而reconstrctPar程序可以指定重构某一段时间的流场:

reconstructPar -time start:end

可以将所需要重构的流场时间范围分成不同的小段,分别重构不同时间段的流场,实现reconstrctPar的伪并行(reconstrctParallel):

#!/bin/bash

# Prompt the user to enter three numbers
echo "Please enter three numbers: startTime endTime procNums >"

# Read the input and save each number to a separate variable
read a b c # startTime endTime np

# Calculate the length of each segment
segmentLength=$(echo "scale=2; ($b - $a) / $c" | bc)

# Initialize an empty array to store the segments
segments=()

# Loop through the number of segments and calculate the start and end points for each segment
for ((i=0; i<$c; i++)); do
  start=$(echo "scale=2; $a + $i * $segmentLength" | bc)
  end=$(echo "scale=2; $start + $segmentLength" | bc)

  # Add the segment to the array
  segments+=("$start $end")
done

# Print the array of segments
echo "${segments[@]}"

ID=1
# Loop through the segments array and execute the command "nohup reconstructPar -time begin:end" for each segment
for segment in "${segments[@]}"; do
  # Extract the start and end points from the segment string
  start=$(echo "$segment" | cut -d' ' -f1)
  end=$(echo "$segment" | cut -d' ' -f2)

  # Execute the command with the start and end points
  nohup reconstructPar -time "$start:$end" &

done

每次调用都要复制这个bash太过于麻烦,我的方法是把这个bash脚本保存到 " ~/bin "路径下,然后将这个路径添加到环境变量,在bashrc中加上这样一行:

PATH=$PATH:~/bin

这样重构流场时只需要输入 “reconstrctParallel”,然后输入 statTime endTime procNums就可以了:

(base) [wli@k012 bubbleUg=0.2-5]$ reconstructParaller
Please enter three numbers: startTime endTime procNums >
0 20 20

程序是在后台运行的,使用了nohup命令,屏幕输入重定向到 “nohup.out” ,可以用“tail -f nohup.out”命令查看,重构结束后,nohup.out文件显示:

(base) [wli@k012 snappyTFM3]$ tail -f nohup.out

Reconstructing point fields

No point fields

No lagrangian fields

Reconstructing sets:
End.

reconstrctPar对CPU占用很少,多开进程也不会影响他人使用:

(base) [wli@k012 bubbleUg=0.2-5]$ top -u wli
top - 17:23:29 up 29 days,  5:20, 16 users,  load average: 9.31, 7.41, 10.39
Tasks: 1912 total,  19 running, 1886 sleeping,   5 stopped,   2 zombie
%Cpu(s): 21.9 us,  1.6 sy,  0.0 ni, 61.7 id, 14.8 wa,  0.0 hi,  0.1 si,  0.0 st
KiB Mem : 13148552+total,   518524 free, 39881476 used, 91085520 buff/cache
KiB Swap:  8388604 total,        0 free,  8388604 used. 90150360 avail Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
179927 wli       20   0  161136  54012  17384 R  50.3  0.0   0:04.30 reconstruct+
179955 wli       20   0  161136  54156  17412 R  50.3  0.0   0:04.06 reconstruct+
179913 wli       20   0  156268  49048  17336 R  48.0  0.0   0:03.88 reconstruct+
179899 wli       20   0  156268  49208  17340 R  46.7  0.0   0:04.05 reconstruct+
179948 wli       20   0  161576  54456  17412 D  46.7  0.0   0:04.21 reconstruct+
179941 wli       20   0  155464  48256  17316 R  44.7  0.0   0:03.99 reconstruct+
179934 wli       20   0  161136  54156  17412 R  44.4  0.0   0:04.06 reconstruct+
179906 wli       20   0  161136  54016  17384 R  42.1  0.0   0:03.82 reconstruct+
179836 wli       20   0  161576  54588  17412 D  40.1  0.0   0:04.10 reconstruct+
179871 wli       20   0  161132  54016  17384 D  39.8  0.0   0:03.91 reconstruct+
179829 wli       20   0  161132  54156  17412 D  38.5  0.0   0:04.12 reconstruct+
179920 wli       20   0  161576  54588  17412 D  38.5  0.0   0:04.01 reconstruct+
179821 wli       20   0  162652  55700  17408 R  37.5  0.0   0:04.07 reconstruct+
179892 wli       20   0  161576  54432  17412 D  37.2  0.0   0:04.30 reconstruct+
179885 wli       20   0  161576  54588  17412 R  36.8  0.0   0:04.12 reconstruct+
179850 wli       20   0  161576  54584  17412 D  36.5  0.0   0:04.00 reconstruct+
179878 wli       20   0  161576  54588  17412 R  35.5  0.0   0:04.11 reconstruct+
179843 wli       20   0  161576  54588  17412 D  34.9  0.0   0:04.24 reconstruct+
179864 wli       20   0  161576  54588  17412 D  34.5  0.0   0:04.01 reconstruct+
179857 wli       20   0  161576  54408  17412 D  34.2  0.0   0:03.78 reconstruct+
179963 wli       20   0  163888   4376   1644 R   1.3  0.0   0:00.10 top
 37992 wli       20   0  965040  60628      0 S   0.0  0.0   0:11.72 hexo
 76318 wli       20   0  152476   2220    900 S   0.0  0.0   0:00.03 sshd
 76325 wli       20   0  121176   3772   1832 S   0.0  0.0   0:00.20 bash
143338 wli       20   0  152780   2828   1240 S   0.0  0.0   0:02.30 sshd
143348 wli       20   0  121184   3844   1852 S   0.0  0.0   0:01.46 bash
143392 wli       20   0  152472   2304    964 S   0.0  0.0   0:00.05 sshd
143404 wli       20   0   55364   2260   1600 S   0.0  0.0   0:00.20 sftp-server
174260 wli       20   0  113144   1184    968 T   0.0  0.0   0:00.00 reconstruct+
174281 wli       20   0  113144   1184    964 T   0.0  0.0   0:00.00 reconstruct+
175276 wli       20   0  113144   1184    964 T   0.0  0.0   0:00.00 reconstruct+
175328 wli       20   0  113144   1184    968 T   0.0  0.0   0:00.00 reconstruct+
175608 wli       20   0  113144   1184    964 T   0.0  0.0   0:00.00 reconstruct+
185785 wli       20   0  152472   2320    972 S   0.0  0.0   0:01.69 sshd
185791 wli       20   0  121180   3788   1844 S   0.0  0.0   0:00.35 bash

 

标签:重构,20,0.0,003,wli,reconstruct,流场,17412,161576
From: https://www.cnblogs.com/sub-group-IPE-wli/p/17276972.html

相关文章

  • 数据库重构探讨系列(1)
    数据库重构探讨系列(1)基础 1、数据库重构分成6类:2、数据库味道与“代码味道”概念相似,代码味道是代码中出现常见问题,表明需要进行重构。数据库味道表明数据库需要重构。这些味道包括:(1)多用途的列如一个列被用于多种用途,就可能存在额外的代码来确保源数据以“正确的方式......
  • 密码学SAT入门003——关于流密码入门算法A5-1的学习
      电子科技大学《现代密码学》慕课截图——感谢聂旭云、廖永建、熊虎等几位老师的讲解                                         算法code A5_1.algprogramdescribe......
  • 低代码平台搭建CRM 加速重构业务模式
    CRM即客户关系管理系统,通过CRM可以有效的管理企业客户数据,帮助企业提升销售业绩以及规范企业企业务流程。客户关系管理不仅仅是一种思想,也是一种管理工具。它的意义是运用......
  • idea重构小技巧3,去掉临时变量
    idea重构小技巧2,去掉临时变量临时变量作为参数传递,很难阅读,提升了代码的阅读难度StringgroupId=context.getProcessModel().getOriginalMqMsg().getAlarmRule().getR......
  • SARS-CoV-2、SARS-CoV (2003)及RaTG13病毒株的S(Spike)蛋白氨基酸序列差异
    在NCBI网站上得到SARS-CoV(2003)、SARS-CoV-2及RaTG13的S蛋白氨基酸序列在clustalOmega进行比对,下面是结果 ......
  • 页面重构不可忽略UED、WPO和SEO的工作(转)
    今天看了迅雷UED团队黄杠杠写的《页面重构做什么》,很不错的一篇文章,节选片段如下:一般来说,接到一个新的需求,以简单的少页面需求为例,流程上可以简单分为几大阶段:1.查看设计稿......
  • 003-Cruehead-CrackMeV3
    第二个需要写注册机首先查看文件,打开文件,什么也没有,help->about,弹出下面的弹窗看来是没有什么线索,直接放进OD里面这里有一个函数CreatFileA,这个函数目的是访问一个文......
  • idea重构小技巧1,选中代码自动提取出来方法
    1.选中抽取方法选中代码右键->refactor->extractmethod生成新的方法,并放在当前同类下2.重新命名新抽取出来的方法为rewriteAlarmObject......
  • idea重构小技巧2,选中变量,抽取为常量
    1.选中写死的内容,抽取为常量2.定义常量名字,默认是INDEX3.常量代码存放地址......
  • 终端启动MYSQL时出现报错:“ERROR 2003 (HY000): Can't connect to MySQL server on 'l
    1.问题说明一直使用:mysql-uroot-p启动mysql数据库,使用是正常的,突然一天启动时候报错:“ERROR2003(HY000):Can’tconnecttoMySQLserveron‘localhost’(1006......