fdtd-openmp-barriers
Table of Contents
Barriers (1D FDTD)
Barriers keep one update phase from reading unfinished results from another. The kernel gets its three per-step barriers from work-sharing constructs rather than explicit omp barrier directives:
#pragma omp for schedule(static) for (size_t k = 0; k < width - 1; k++) { Hy[k] = Ch1[k] * Hy[k] + Ch2[k] * (Ez[k + 1] - Ez[k]); } // implicit barrier: all Hy updates complete #pragma omp for schedule(static) for (size_t k = 1; k < width; k++) { Ez[k] = Ce1[k] * Ez[k] + Ce2[k] * (Hy[k] - Hy[k - 1]); } // implicit barrier: all Ez updates complete #pragma omp single { Fdtd_EzSourcesApply(sim->fsim_sources, sim); Fdtd_EzStateNextStep(sim->fsim_state); } // implicit barrier: sources and counter complete
The added comments mark the synchronization points. Removing the first barrier with nowait could let an electric update read old magnetic values from another thread's block. Removing the final barrier could let the next magnetic phase race with source injection.
Each barrier also has a cost. On small grids, little useful work separates them, which can make parallel execution slower than serial execution.
Source: fdtd_ez_kernels.c.
fdtd-openmp-barriers.md · Last modified: by 127.0.0.1
