24小时热门版块排行榜    

查看: 501  |  回复: 0

_yixiao

铁虫 (小有名气)

[交流] 【求助】传热计算的OpenMP并行计算

请大家帮帮忙
在温度场的计算过程中,时间步长上的迭代过程是相互关联,相互影响的。一次迭代需要使用上一次迭代的运算结果,故迭代之间不宜实现并行化。而在一次迭代内部,温度场的计算仅需要前一次时刻的计算结果,各个计算过程之间没有影响,可以进行并行计算。但我进行以下的并行计算后结果同串行相差很大,且计算时间反而增加。
以下即是我的并行程序,用到的OpenMP指令是section指令:
(其中,程序中的h_w_f,Water_Tem_in,Mould_dt,Mould_dy等为全局变量,AA、BB、C_mould,float Density_mould等为局部变量,q1,Q2,q3,Q4为调用函数。)
for(k=0;k<100;k++)
{


                for(i=0;i<=xx;i++)
                {
                        for(j=0;j<=yy;j++)
                        {                               
                                thermal_1[j]=thermal_0[j];
                        }
                }  


#pragma omp parallel sections
                {
#pragma omp section   
                  
                        {



                                for(i=0;i<=xx;i++)
                                {
                                        for(j=0;j<=yA;j++)
                                        {
                                if (i==xK && j==0)//K
                                {
                                        thermal_0[j] = float(2*AA*thermal_1[i+1][j]+2*BB*thermal_1[j+1]+thermal_1[j]*(1-2*AA-2*BB)
                                                +2*h_w_f*(Water_Tem_in - thermal_1[j])*Mould_dt/(Mould_dy*C_mould*Density_mould));
                                }
                                else if (i==xJ && j==0)//J
                                {
                                        thermal_0[j] = float(2*AA*thermal_1[i-1][j]+2*BB*thermal_1[j+1]+thermal_1[j]*(1-2*AA-2*BB)
                                                +2*h_w_f*(Water_Tem_in - thermal_1[j])*Mould_dt/(Mould_dy*C_mould*Density_mould));
                                }


                                //////////[side]
                                else if ((i>=xK && i<=xJ) && j==0)//KJ
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+2*BB*(thermal_1[j+1])
                                                +thermal_1[j]*(1-2*AA-2*BB)
                                                +2*h_w_f*(Water_Tem_in - thermal_1[j])*Mould_dt/(Mould_dy*C_mould*Density_mould));
                                }
                                else if (i==xJ && (j>=0 && j<=yA))//JP
                                {
                                        thermal_0[j] = float(2*AA*(thermal_1[i-1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])
                                                +thermal_1[j]*(1-2*AA-2*BB));
                                }
                                else if ((i>=xK && i<=xJ) && j==yA)//PL
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+2*BB*(thermal_1[j-1])
                                                +thermal_1[j]*(1-2*AA-2*BB)+2*Q4(i-xK)*Mould_dt/(Mould_dy*C_mould*Density_mould));   
                                }
                                else if (i==xK && (j>=0 && j<=yA))//LK
                                {
                                        thermal_0[j] = float(2*AA*(thermal_1[i+1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])+thermal_1[j]*(1-2*AA-2*BB));
                                }
                                else if ((i>=xK && i<=xJ) && (j<=yA) )// fix
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])+thermal_1[j]*(1.0-2*AA-2*BB));
                                }





                                        }
                                       
                        }
                }

#pragma omp section                        
                        {
                                for(i=0;i<=xx;i++)
                                {
                                        for(j=yB;j<=yy;j++)
                                        {
                                if (i==xJ && j==yy)//E
                                {
                                        thermal_0[j] = float(2*AA*thermal_1[i-1][j]+2*BB*thermal_1[j-1]+thermal_1[j]*(1-2*AA-2*BB)
                                                +2*h_w_l*(Water_Tem_in - thermal_1[j])*Mould_dt/(Mould_dy*C_mould*Density_mould));
                                }
                                else if (i==xK && j==yy)//D
                                {
                                        thermal_0[j] = float(2*AA*thermal_1[i+1][j]+2*BB*thermal_1[j-1]+thermal_1[j]*(1-2*AA-2*BB)
                                                +2*h_w_l*(Water_Tem_in - thermal_1[j])*Mould_dt/(Mould_dy*C_mould*Density_mould));
                                }

                                ////side
                                else if ((i>=xK && i<=xJ) && j==yB)//MN
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+2*BB*(thermal_1[j+1])
                                                +thermal_1[j]*(1-2*AA-2*BB)+2*Q2(i-xK)*Mould_dt/(Mould_dy*C_mould*Density_mould));
                                }
                                else if (i==xJ && (j>=yB && j<=yy))//NE
                                {
                                        thermal_0[j] = float(2*AA*(thermal_1[i-1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])+thermal_1[j]*(1-2*AA-2*BB));
                                }
                                else if ((i>=xK && i<=xJ) && j==yy)//ED
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+2*BB*(thermal_1[j-1])+thermal_1[j]*(1-2*AA-2*BB)
                                                +2*h_w_l*(Water_Tem_in - thermal_1[j])*Mould_dt/(Mould_dy*C_mould*Density_mould));
                                }
                                else if (i==xK && (j>=yB && j<=yy))//DM
                                {
                                        thermal_0[j] = float(2*AA*(thermal_1[i+1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])+thermal_1[j]*(1-2*AA-2*BB));
                                }

                                else if((i>=xK && i<=xJ) && (j>=yB))// loose
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])+thermal_1[j]*(1.0-2*AA-2*BB));
                                }



                                        }
                                }
                        }


#pragma omp section   
                        {
                                for(i=0;i<=xK;i++)
                                {
                                        for(j=yA;j<=yB;j++)
                                        {
                                if (i==0 && j==yA)//A
                                {
                                        thermal_0[j] = float(2*AA*thermal_1[i+1][j]+2*BB*thermal_1[j+1]+thermal_1[j]*(1-2*AA-2*BB)
                                                +2*h_n_l*(Water_Tem_in - thermal_1[j])*Mould_dt/(Mould_dx*C_mould*Density_mould));
                                }
                                else if (i==0 && j==yB)//B
                                {
                                        thermal_0[j] = float(2*AA*thermal_1[i+1][j]+2*BB*thermal_1[j-1]+thermal_1[j]*(1-2*AA-2*BB)
                                                +2*h_n_l*(Water_Tem_in - thermal_1[j])*Mould_dt/(Mould_dx*C_mould*Density_mould));
                                }
                                else if (i==xK && j==yA)//L
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])+thermal_1[j]*(1-2*AA-2*BB)
                                                +Q4(i-xK)*Mould_dt/(Mould_dy*C_mould*Density_mould)+q1(j)*Mould_dt/(Mould_dx*C_mould*Density_mould));
                                }
                                else if (i==xK && j==yB)//M
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])+thermal_1[j]*(1-2*AA-2*BB)
                                                +Q2(i-xK)*Mould_dt/(Mould_dy*C_mould*Density_mould)+q1(j)*Mould_dt/(Mould_dx*C_mould*Density_mould));
                                }
///side
                                else if ((i>=0 && i<=xK) && j==yA)//AL
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+2*BB*(thermal_1[j+1])+thermal_1[j]*(1-2*AA-2*BB));
                                }
                                else if (i==xK && (j>=yA && j<=yB))//LM
                                {
                                        thermal_0[j] = float(2*AA*(thermal_1[i-1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])
                                                +thermal_1[j]*(1-2*AA-2*BB)+2*q1(j)*Mould_dt/(Mould_dx*C_mould*Density_mould));
                                }
                                else if ((i>=0 && i<=xK) && j==yB)//MB
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+2*BB*(thermal_1[j-1])+thermal_1[j]*(1-2*AA-2*BB));   
                                }
                                else if (i==0 && (j>=yA && j<=yB))//BA
                                {
                                        thermal_0[j] = float(2*AA*(thermal_1[i+1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])+thermal_1[j]*(1-2*AA-2*BB)
                                                +2*h_n_l*(Water_Tem_in - thermal_1[j])*Mould_dt/(Mould_dx*C_mould*Density_mould));
                                }
   
                                else if (i<=xK  && (j>=yA && j<=yB))// left
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])+thermal_1[j]*(1.0-2*AA-2*BB));
                                }


                                        }
                                }
                        }


#pragma omp section   
                        {
                                for(i=xJ;i<=xx;i++)
                                {
                                        for(j=yA;j<=yB;j++)
                                        {
                                if (i==xJ && j==yA)//P
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])+thermal_1[j]*(1-2*AA-2*BB)
                                                +Q4(i-xK)*Mould_dt/(Mould_dy*C_mould*Density_mould)+q3(j)*Mould_dt/(Mould_dx*C_mould*Density_mould));
                                }
                                else if (i==xx && j==yA)//H
                                {
                                        thermal_0[j] = float(2*AA*thermal_1[i-1][j]+2*BB*thermal_1[j+1]+thermal_1[j]*(1-2*AA-2*BB)
                                                +2*h_n_r*(Water_Tem_in - thermal_1[j])*Mould_dt/(Mould_dx*C_mould*Density_mould));
                                }
                                else if (i==xJ && j==yB)//N
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])+thermal_1[j]*(1-2*AA-2*BB)
                                                +Q2(i-xK)*Mould_dt/(Mould_dy*C_mould*Density_mould)+q3(j)*Mould_dt/(Mould_dx*C_mould*Density_mould));
                                }
                                else if (i==xx && j==yB)//G
                                {
                                        thermal_0[j] = float(2*AA*thermal_1[i-1][j]+2*BB*thermal_1[j-1]+thermal_1[j]*(1-2*AA-2*BB)
                                                +2*h_n_r*(Water_Tem_in - thermal_1[j])*Mould_dt/(Mould_dx*C_mould*Density_mould));
                                }
////side
                                else if ((i>=xJ && i<=xx) && j==yA)//PH
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+2*BB*(thermal_1[j+1])+thermal_1[j]*(1-2*AA-2*BB));
                                }
                                else if (i==xx && (j>=yA && j<=yB))//HG
                                {
                                        thermal_0[j] = float(2*AA*(thermal_1[i-1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])
                                                +thermal_1[j]*(1-2*AA-2*BB)+2*h_n_r*(Water_Tem_in - thermal_1[j])*Mould_dt/(Mould_dx*C_mould*Density_mould));
                                }
                                else if ((i>=xJ && i<=xx) && j==yB)//GN
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+2*BB*(thermal_1[j-1])+thermal_1[j]*(1-2*AA-2*BB));   
                                }
                                else if (i==xJ && (j>=yA && j<=yB))//NP
                                {
                                        thermal_0[j] = float(2*AA*(thermal_1[i+1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])
                                                +thermal_1[j]*(1-2*AA-2*BB)+2*q3(j)*Mould_dt/(Mould_dx*C_mould*Density_mould));
                                }


                                else if ( i>=xJ && (j>=yA && j<=yB))// right
                                {
                                        thermal_0[j] = float(AA*(thermal_1[i-1][j]+thermal_1[i+1][j])+BB*(thermal_1[j-1]+thermal_1[j+1])+thermal_1[j]*(1.0-2*AA-2*BB));
                                }
       

                                        }
                                }

                        }               


                }  
}
回复此楼

» 猜你喜欢

信仰我所必须相信的
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 _yixiao 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 0703化学336分求调剂 +3 zbzihdhd 2026-03-15 3/150 2026-03-16 16:44 by 我的船我的海
[考研] 283求调剂 +10 小楼。 2026-03-12 14/700 2026-03-16 16:08 by 13811244083
[考研] 一志愿华中师范071000,325求调剂 +6 RuitingC 2026-03-12 6/300 2026-03-16 14:50 by 可淡不可忘
[考研] 311求调剂 +6 冬十三 2026-03-15 6/300 2026-03-16 08:00 by wang_dand
[考研] 289求调剂 +5 步川酷紫123 2026-03-11 5/250 2026-03-15 00:45 by kruisytel
[考研] 268求调剂 +5 一定有学上- 2026-03-14 6/300 2026-03-14 22:20 by 运气yunqi
[考研] 材料与化工 323 英一+数二+物化,一志愿:哈工大 本人本科双一流 +4 自由的_飞翔 2026-03-13 5/250 2026-03-14 19:39 by hmn_wj
[考研] 265求调剂 +4 威化饼07 2026-03-12 4/200 2026-03-14 17:23 by userper
[考研] 复试调剂 +4 z1z2z3879 2026-03-14 5/250 2026-03-14 16:30 by JourneyLucky
[考研] 材料与化工(0856)304求B区调剂 +7 邱gl 2026-03-10 11/550 2026-03-14 12:18 by 邱gl
[考研] 学硕285求调剂 +13 Wisjxn 2026-03-12 46/2300 2026-03-14 10:33 by JourneyLucky
[考研] 云南财经大学信息学院计算机学硕专硕学位点 +3 zjptai 2026-03-10 5/250 2026-03-14 01:23 by 飞行琦
[基金申请] 有必要更换申报口吗 20+3 fannyamoy 2026-03-11 3/150 2026-03-14 00:52 by zhanghaozhu
[考研] 336求调剂 +6 Iuruoh 2026-03-11 6/300 2026-03-13 22:06 by JourneyLucky
[考研] 301求调剂 +6 Liyouyumairs 2026-03-11 6/300 2026-03-13 20:11 by JourneyLucky
[考研] 【0856】化学工程(085602)313 分,本科学科评估A类院校化学工程与工艺,诚求调剂 +7 小刘快快上岸 2026-03-11 7/350 2026-03-13 16:06 by ruiyingmiao
[考研] 土木第一志愿276求调剂,科研和技能十分丰富,求新兴方向的导师收留 +3 土木小天才 2026-03-12 3/150 2026-03-13 15:01 by JourneyLucky
[考研] 070303一志愿西北大学学硕310找调剂 +3 d如愿上岸 2026-03-13 3/150 2026-03-13 10:43 by houyaoxu
[考研] 0857环境调剂 +5 熠熠_11 2026-03-10 5/250 2026-03-11 10:59 by wang_dand
[考研] 085602化工求调剂 +7 董boxing 2026-03-10 7/350 2026-03-10 17:07 by BruceLiu320
信息提示
请填处理意见