Problem in shifting from sequential to parallel

Dear community members,

I’m very new parallel computing, till now I wrote sequential codes, due to time constrain I have to complete my masters by next month end. So I started doing parallel computations. while solving the unsteady NS equations even by increasing the number of processors my commutation speed is not increasing. More over I’m feeling like my sequential code faster than parallel code. Here is the code snippt for time integration of my script and I have doubt on this part . If any knows what is the bottle neck in my code please let know.

for (int n=rep+1; n<=iter; n++)
{		
		if(mpirank == 0)
			cout << " i = " << n  << "\n";
			cout << " tps = " << tps  << "\n";
		
		tps=tps+dt;
		{
		[upr,upt,upz,pp] = [ur,ut,uz,p];
		macro def(i)[i, i#B, i#C, i#D]//
		macro init(i)[i, i, i, i]//
		createMat(Th, NSMAT, Pk);
		NSMAT = NS(Uh,Uh,tgv  = -1);
		rhs1[] = NSRITE(0,Uh,tgv = -1);
		ur[] = NSMAT^-1*rhs1[];
		}		
}

You help will be highly appreciated. Thank you in advance

Good regards,
sumen.

I think you could move the createMat(Th, NSMAT, Pk); out of the loop, you need that only once. Then, NSMAT = NS(Uh,Uh,tgv = -1); is enough to update the matrix. But without the complete code, it is hard to help.

Thanks for reply, here my code please have a look. between its a 2D problem with 3 velocity fields and pressure. There is no variation of velocities in 3rd direction that why 2D

load "PETSc"
macro dimension()2// EOM
include "macro_ddm.idp"


func Pk = [P2,P2,P2,P1];

////////////////////////////// Mesh /////////////////////////////////


		mesh Th;
		Th = readmesh("......");

cout << "Number of Elements on Rank before buildDmesh(Th) "<< mpirank<<":   "<< Th.nt << endl;

Mat NSMAT;
buildDmesh(Th);
{
  macro def(i)[i, i#B, i#C, i#D]//
  macro init(i)[i, i, i, i]//
  createMat(Th, NSMAT, Pk);
}

cout << "Number of Elements on Rank after buildDmesh(Th) "<< mpirank<<":   "<< Th.nt << endl;

real Re = 300;
real nu = 1/Re;



/////////////////////// Finite element spaces /////////////////////////////////////////
fespace Uh(Th,Pk);

Uh [ur,ut,uz,p]; //// Flow field for the present time step

Uh [vr,vt,vz,q]; //// Test functions

Uh [upr,upt,upz,pp]; //// Flow field for the previous time step

Uh [rhs1,rhs2,rhs3,rhs4]; //// Right hand side of the NS formed by the terms from the previous time step



varf  NS ([ur,ut,uz,p],[vr,vt,vz,q])=
    		 int2d(Th)(
   variational formulation of linear terms  + BCs
);
       // Boundary cond.


varf NSRITE ([ur,ut,uz,p],[vr,vt,vz,q])=
			int2d(Th)( variational formulation of non linear terms + BCs );

set(NSMAT, sparams = "-ksp_view_final_residual -pc_type hypre");

{
[ur,ut,uz,p] = [0.0,0.0,0.0,0.0];
plotD(Th,ur,cmm="plot of ur on processor 0");
plotD(Th,ut,cmm="plot of ut on processor 0");
plotD(Th,uz,cmm="plot of uz on processor 0");
}

for (int n=rep+1; n<=iter; n++)
{		
		if(mpirank == 0)
			cout << " i = " << n  << "\n";
			cout << " tps = " << tps  << "\n";
		
		tps=tps+dt;
		{
		[upr,upt,upz,pp] = [ur,ut,uz,p];
		macro def(i)[i, i#B, i#C, i#D]//
		macro init(i)[i, i, i, i]//
		createMat(Th, NSMAT, Pk);
		NSMAT = NS(Uh,Uh,tgv  = -1);
		rhs1[] = NSRITE(0,Uh,tgv = -1);
		ur[] = NSMAT^-1*rhs1[];
		}		
}

Why are you calling createMat in the for loop?

Now I have commented the createMat in for loop still, the code is taking the saame time

Depending on your machine and the solver you used, that’s to be expected.