Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

omp parallel sections failed,why?

chbq
Beginner
269 Views
hello,I am sorry to submit a C++ problem here,becaue I think here have much users than the Intel C++ community.maybe I can get more help form others.
I can parallel a simple program and get the accelerate rate about 1.4 or more on my computer,my computer information is :
Pentium 3.00, support Hyper-Threading technology,1G memory,
window xp sp2 operation system.
the serial way
sum=ParallelFun(0,LL,LL,MM,NN);
and the parallel way :
#pragma omp parallel sections
{
#pragma omp section
sum1=ParallelFun(0,LL/2,LL,MM,NN);
#pragma omp section
sum2=ParallelFun(LL/2,LL,LL,MM,NN);
}
the ParallelFun is here:
double ParallelFun(int start,int end,int L,int M,int N)
{
double temp1,temp2,temp3;
double temp=0;
double t;
int i,j,k;
for(i=start;ifor (j=0;jfor(k=0;k{
temp1=i*M*N;
temp2=j*N;
temp3=k*L;
t=sin(temp1)+cos(temp2)+tan(temp3+temp2+temp1);
temp+=t;

}
return temp;
}
However ,when I using such ways to parallelize another program,I am failed,
thefunction isabout 5KB,it is very long,and involved many large data, the following is part of the function:
bool CMainFarme::TemperatureCalculation()
{
....
memcpy(Tn,Tt,(long)LT*MT*NT*4);
for(i=0;ifor(j=0;jfor(k=0;k{
first=(long)i*MNT+(long)j*NT+k;//***
if((int)Att[first]!=1 && (int)Att1[first]!=103)
{
if(Att[first]==Att[first+MNT])
Axr=cThermal.Htcf[Att[first]];
else
{
if(Att1[first+MNT]==103)
Axr=0;
else
Axr=2.0/(Htcf0[Att[first]]+Htcf0[Att[first+MNT]]+2.0/ (dFluidP.ST*cThermal.Fhm[Att[first]][Att[first+MNT]]));
}
if(...)
.....
else
....
.......
if(...)
return FALSE;
......
return TRUE;
}
}
the LT*MT*NT is always more than 1 000 000 or more ,the other globalvariables such as Att,Att1 are also as large as Tn and Tt,and the functioncontain many if-else clausesstruct as list above(about to 10 if-else clauses). I use the same way to split the function into two sub-function(because they have return false in function,can't use omp parallel for clause) as fellow:
declaration in MainFrame.h :
public:
BOOL ParallelTempCalOnly(int start, int end, int LT, int MT, int NT, float* Tn, float* Tt,float *Htcf0);
call in a function :
BOOL CMainFrame::TempCalOnly()
{
...
#pragma omp parallel sections
{
#pragma omp section
ParallelTempC alOnly(0,LT/2,LT,MT,NT,Tn,Tt,Htcf0);
#pragma omp section
ParallelTempCalOnly(LT/2,LT,LT,MT,NT,Tn,Tt,Htcf0);
}
...
}
compile the program and execute the exe file,It's output the right result as the serial one,but they does not parallelized, the CPU using is about %50,indicate that another CPU is idle, while I execute the above simple program ,the CPU using is %100 when execute the parallel part of the program.
my platform is Visual studio 2003+intel c++ 9.0. I want to know why it is not parallel ,is the function too long? or the variable int the function contains too much data ? thanks
0 Kudos
3 Replies
TimP
Honored Contributor III
269 Views
If you don't have faith in the C forum, why not use the threading forum? I'm somewhat surprised that your smaller example would perform so well with only HyperThreading support for multiple threads. Could you learn anything from -Qopenmp-report2 ?
0 Kudos
chbq
Beginner
269 Views

I am very sorry to submit a question here,I never do it in future.

my small example isperform well on my computer,I am tell the truth,the full codes are here, I say that the accelerate rateis 1.4 or more,that is a graphical user interface program,I click a button and start to compute the following code,I compiled them in Visual studio 2003 integrated with intel c++9.0,it is a Debug Version,it's slower than the program compiled by the intel c++ with command line and without GUI support. if compile them by intel c++ command line,I am amazed by the result.

#include
#include
#include
#include "omp.h"

using namespace std;

#define LL 400
#define MM 400
#define NN 400

double sum=0;
double ParallelFun(int start,int end,int L,int M,int N);

int main(int argc, char* argv[])
{
DWORD t1=GetTickCount();
cout<<"Serial Program is running..."<sum=ParallelFun(0,LL,LL,MM,NN);
cout<<"Serial program is ended "<cout<<"sum=:"<<DWORD t2=GetTickCount();
cout<<"The total time is :"<<<

DWORD t3=GetTickCount();
cout<<"parallel Program is running..."<sum=0;
double sum1,sum2;
#pragma omp parallel sections
{
#pragma omp section
sum1=ParallelFun(0,LL/2,LL,MM,NN);
#pragma omp section
sum2=ParallelFun(LL/2,LL,LL,MM,NN);
}
cout<<"sum1="<<cout<<"sum2="<<sum=sum1+sum2;
cout<<"parallel program is ended "<cout<<"sum=:"<<DWORD t4=GetTickCount();
cout<<"The total time is :"<<cout<<"Accelerate rate is :"<<(t2-t1)*1.0/(t4-t3)*1.0<}
double ParallelFun(int start,int end,int L,int M,int N)
{
double temp1,temp2,temp3;
double temp=0;
double t;
int i,j,k;
for(i=start;ifor (j=0;jfor(k=0;k{
temp1=i*M*N;
temp2=j*N;
temp3=k*L;
t=sin(temp1)+cos(temp2)+tan(temp3+temp2+temp1);
temp+=t;

}
return temp;
}

D:2003 estsections>icl testsections.cpp /Qopenmp
Intel C++ Compiler for 32-bit applications, Version 9.0 Build 20051130Z Pa
ckage ID: W_CC_C_9.0.028
Copyright (C) 1985-2005 Intel Corporation. All rights reserved.

testsections.cpp
testsections.cpp(33) : (col. 1) remark: OpenMP DEFINED SECTION WAS PARALLELIZED.

Microsoft Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.

-out:testsections.exe
-nodefaultlib:libguide_stats.lib
-nodefaultlib:libguide40_stats.lib
-defaultlib:libguide.lib
testsections.obj

D:2003 estsections>testsections.exe
Serial Program is running...
Serial program is ended
sum=:-1.49431e+007
The total time is :19266

parallel Program is running...
sum1=-2.01281e+007
sum2=5.18504e+006
parallel program is ended
sum=:-1.49431e+007
The total time is :6344
Accelerate rate is :3.03689

D:2003 estsections>testsections.exe
Serial Program is running...
Serial program is ended
sum=:-1.49431e+007
The total time is :19234

parallel Program is running...
sum1=-2.01281e+007
sum2=5.18504e+006
parallel program is ended
sum=:-1.49431e+007
The total time is :6344
Accelerate rate is :3.03184

I ama mazed that the accelerate rateislarger than 2 in theory,and I can not using /Qopenmp-report2 option,maybe is my install problem.

D:2003 estsections>icl testsections.cpp /Qopenmp-report2
Intel C++ Compiler for 32-bit applications, Version 9.0 Build 20051130Z Pa
ckage ID: W_CC_C_9.0.028
Copyright (C) 1985-2005 Intel Corporation. All rights reserved.

testsections.cpp
testsections.cpp(33): warning #161: unrecognized #pragma
#pragma omp parallel sections
^

testsections.cpp(35): warning #161: unrecognized #pragma
#pragma omp section
^

testsections.cpp(37): warning #161: unrecognized #pragma
#pragma omp section
^

Microsoft Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.

-out:testsections.exe
testsections.obj

0 Kudos
TimP
Honored Contributor III
269 Views
The unrecognized pragma message comes out because you omitted /Qopenmp
0 Kudos
Reply