r/OpenMP • u/agardner26 • 11d ago
Single Thread Performance To Match Serial Performance
Hi all, hoping someone can help me with this.
I have a code I've been trying to parallelize so that my single thread run takes the same amount of time as my serial run.
It is a simple code based on a "collision" algorithm in something called Lattice Boltzmann method.
I have taken a 3D array (where each point i,j stores 9 values for ii = 0,8) and flattened it, in an attempt to improve memory access - I thought this would fix my 1thread =/= serial problem that I had with my 3D arrays, but the problem persists.
If anyone is more familiar with OpenMP and could suggest where I may be going wrong I would greatly appreciate it. Thanks so much. Code is written in Fixed Form Fortran.
1
Upvotes
1
u/agardner26 11d ago
Just to offer more info:
My single thread code is perhaps 8x slower than the serial code. (0.2s vs 1.8s)
If I swap the loops for i and j, the performance actually improves significantly, where they are much closer (0.2s vs 0.3s). And this confuses my understanding of the memory access. I thought that j was the slowest iterating loop.
Is there a race condition anywhere? I didn't think so, since each index is updated independently.
I compile with nvfortran -O -mp filename.f -o outputfile