小技巧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