Hello Everyone, I hope everyone is safe and healthy in this tough covid conditions.
Actually I have been given a complex C code for doing various calculations. I have written the corresponding CUDA C code for doing those calculations. Now my job is to parallelise the code so that computational time decreases. I have done some basic examples of parallelisation also. I need some suggestions as to how to start doing parallelisation in my CUDA code snippet which is attached below:
A big heartiest thanks in advance.
//////////////Pre-calculation of tot_cnlm_sum_p for every atom/////////////////
for(h=0; h<natoms; h++)
{
for(jt=0; jt<natoms;jt++)
{
if(h != jt)
{
dx=(x11[h]-x11[jt]);
dy=(y11[h]-y11[jt]);
dz=(z11[h]-z11[jt]);
r2 =dx*dx + dy*dy + dz*dz;
r=sqrtf(r2);
pcolhea1 = acosf(dz/r);
for (l=0;l<lmax;l++)
{
if (l==0)
{
Lmn[0]=1.0;
Lmn_all[jt][0][0] = 1.0;
}
else
{
legendre(lmax,l,pcolhea1,Lmn);
}
for(b_m=0;b_m<19;b_m++)
{
if(b_m<2*l+1)
{
m= -l + b_m;
if (m >= 0)
{
Lmn_all[jt][l][m]= Lmn[m];
}
}
}
}
}
}
k2=9;
for(n=0;n<etaang;n++)
{
for(ll=0;ll<lmax;ll++)
{
p_ch_p= make_cuDoubleComplex(0,0);
for(b_mm=0;b_mm<19;b_mm++)
{
if(b_mm<2*ll+1)
{
xt2 = make_cuDoubleComplex(0,0);
for(ju=0; ju<natoms;ju++)
{
if(h != ju)
{
dx=(x11[h]-x11[ju]);
dy=(y11[h]-y11[ju]);
dz=(z11[h]-z11[ju]);
r2 =dx*dx + dy*dy + dz*dz;
r=sqrtf(r2);
fophi1= atan2f(dy,dx);
if (r <= rcut)
{
rcutfun = make_cuDoubleComplex(0.5*(cosf(pi*r*rcut_inv)+1),0);
}
else
{
rcutfun = make_cuDoubleComplex(0,0);
}
//func1 = expf(-netaa[n]*r2);
temp50 = -netaa[n]*r2;
temp51 = make_cuDoubleComplex(temp50,0);
func1 = my_complex_exp (temp51);
term1 = cuCmul(func1,rcutfun);
G_p = term1;
mm = -ll+b_mm;
m_1 = abs(mm);
m_1_1 = m_1*hv;
if (mm<0)
{
temp1 = cuCmul(q, make_cuDoubleComplex(m_1_1,0));
ex1 = cuCmul(temp1, make_cuDoubleComplex(fophi1,0));
comp_1_w = my_complex_exp(ex1);
}
else
{
temp2 = cuCmul(q, make_cuDoubleComplex(m_1,0));
ex2 = cuCmul(temp2, make_cuDoubleComplex(fophi1,0));
ex3 = my_complex_exp(ex2);
float result = 1.0;
int zz;
for(zz=9; zz>=1; zz--)
{
if(zz<=mm)
{
result *= (hv);
}
}
comp_1_w = cuCmul(ex3, make_cuDoubleComplex(result, 0));
}
cons1_temp = cons1[ll][b_mm];
mult1 = cuCmul(comp_1_w, make_cuDoubleComplex(cons1_temp, 0));
Lmmnn = Lmn_all[ju][ll][m_1];
useY1 = cuCmul(mult1, make_cuDoubleComplex(Lmmnn, 0));
mult4 = cuCmul(useY1,G_p);
xt2 = cuCadd(xt2,mult4);
}
}
xt6 = cuConj(xt2);
temp3 = cuCmul(xt2,xt6);
p_ch_p = cuCadd(p_ch_p,temp3); //p_ch_p = p_ch_p + (xt2 * xt6);
tot_cnlm_sum_p[h][n][ll][b_mm] = xt2;
}
}
sub1 = 1/(gtotmax_f[k2]-gtotmin_f[k2]);
cons2 = ((4*pi)/(float)(2*ll+1));
temp4 = cuCmul(p_ch_p,make_cuDoubleComplex(cons2,0));
temp5[k2] = meangtot_f[k2] + gtotmin_f[k2];
temp100 = temp5[k2];
temp6 = cuCsub(temp4, make_cuDoubleComplex(temp100,0));
GiS_p[h][k2] = cuCmul(temp6, make_cuDoubleComplex(sub1,0));
k2=k2+1;
}
}
}
