url: https://dazuozcy.github.io/posts/introdution-to-openmp-intel/#23-%E5%8F%AF%E6%80%95%E7%9A%84%E4%B8%9C%E8%A5%BF%E5%86%85%E5%AD%98%E6%A8%A1%E5%9E%8Batomicsflushpairwise%E5%90%8C%E6%AD%A5%20
新手并行程序员与专家并行程序员之间的区别是专家have a collection of these fundamental design patterns in their minds.
SPMD
Single Program Multiple Data: Run the same program on P processing elements where P can be arbitrarily large.
Use the rank - an ID ranging from 0 to (P-1) - to select between a set of tasks and to manage any shared data structures.
例子:
#include "omp.h"
void main()
{
int i, step;
double pi = 0.0, sum = 0.0;
step = 1.0 / (double)num_steps;
#pragma omp parallel firstprivate(sum) private(x, i)
{
int id = omp_get_threads_num();
int numprocs = omp_get_num_threads();
int step1 = id * num_steps / numprocs;
int stepN = (id+1) * num_steps / numprocs