24小时热门版块排行榜    

查看: 619  |  回复: 1

_yixiao

铁虫 (小有名气)

[交流] 【求助】传热计算的OpenMP并行计算 已有1人参与

请大家帮帮忙
在温度场的计算过程中,时间步长上的迭代过程是相互关联,相互影响的。一次迭代需要使用上一次迭代的运算结果,故迭代之间不宜实现并行化。而在一次迭代内部,温度场的计算仅需要前一次时刻的计算结果,各个计算过程之间没有影响,可以进行并行计算。但我进行以下的并行计算后结果同串行相差很大,且计算时间反而增加,不知道问题出在哪里。
以下即是我的并行程序,用到的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));
                                }
        

                                        }
                                }

                        }               


                }  
}

本文来自: 小木虫论坛 http://muchong.com/bbs/viewthread.php?tid=2410411
回复此楼
信仰我所必须相信的
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

frankliu

禁虫 (正式写手)

★ ★ ★
小木虫(金币+0.5):给个红包,谢谢回帖交流
mze04532(金币+2):鼓励一下,欢迎交流~ 2010-09-28 19:38:41
本帖内容被屏蔽

2楼2010-09-28 13:45:51
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 _yixiao 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 211本,11408一志愿中科院277分,曾在中科院自动化所实习 +3 Losir 2026-03-12 4/200 2026-03-16 21:52 by Losir
[考研] 东南大学364求调剂 +5 JasonYuiui 2026-03-15 5/250 2026-03-16 21:28 by 木瓜膏
[考研] 材料专硕306英一数二 +4 z1z2z3879 2026-03-16 6/300 2026-03-16 19:38 by z1z2z3879
[考研] 333求调剂 +3 文思客 2026-03-16 7/350 2026-03-16 18:21 by 文思客
[考研] 070300化学学硕求调剂 +6 太想进步了0608 2026-03-16 6/300 2026-03-16 16:13 by kykm678
[考研] 中科院材料273求调剂 +4 yzydy 2026-03-15 4/200 2026-03-16 15:59 by Gaodh_82
[考研] 326求调剂 +3 mlpqaz03 2026-03-15 3/150 2026-03-16 07:33 by Iveryant
[考研] 288求调剂 +4 奇点0314 2026-03-14 4/200 2026-03-14 23:04 by JourneyLucky
[考研] 一志愿安徽大学材料工程专硕313分,求调剂的学校 +8 Yu先生 2026-03-10 10/500 2026-03-14 01:04 by JourneyLucky
[考研] 327求调剂 +4 Ffff03 2026-03-10 4/200 2026-03-14 00:17 by JourneyLucky
[考研] 285 求调剂 资源与环境 一志愿北京化工大学 +3 未名考生 2026-03-10 3/150 2026-03-13 23:04 by JourneyLucky
[考研] 337一志愿华南理工0805材料求调剂 +7 mysdl 2026-03-11 9/450 2026-03-13 22:43 by JourneyLucky
[考研] 材料与化工304求B区调剂 +5 邱gl 2026-03-11 6/300 2026-03-13 22:37 by JourneyLucky
[考研] 26调剂/材料/英一数二/总分289/已过A区线 +6 步川酷紫123 2026-03-13 6/300 2026-03-13 21:59 by 星空星月
[考研] 0703化学一志愿211 总分320求调剂 +5 玛卡巴卡啊哈 2026-03-11 5/250 2026-03-13 21:40 by JourneyLucky
[考研] 311求调剂 +3 冬十三 2026-03-13 3/150 2026-03-13 20:41 by JourneyLucky
[考研] 0817化学工程与技术考研312分调剂 +3 T123 tt 2026-03-12 3/150 2026-03-13 10:49 by houyaoxu
[考研] 收调剂 +7 调剂的考研学生 2026-03-10 7/350 2026-03-10 17:57 by 麦茶汤圆
[考研] 0703化学调剂 +3 三dd. 2026-03-10 3/150 2026-03-10 15:45 by peike
[硕博家园] 木虫好像不热闹了,是不是? +4 偏振片 2026-03-10 4/200 2026-03-10 09:51 by longwave
信息提示
请填处理意见