寻找 OpenMP 和 MPI 的 Flynn 分类法代码示例

Looking for Flynn's taxonomy code example for OpenMP and MPI

正在寻找 C/C++ 或 Python 代码的所有弗林分类法示例代码以供理解

任何代码都可以,我只是想学点东西。我试图找到其中一些但没有结果。

SIMD
SISD
MISD
MIMD

Looking for all Flynn's Taxonomy example code for C/C++ or Python code for understanding

分类法更多地是关于计算机体系结构的 per se.

让我们开始SIMD,从Wikipedia可以读到:

Single instruction, multiple data (SIMD) is a class of parallel computers in Flynn's taxonomy.It describes computers with multiple processing elements that perform the same operation on multiple data points simultaneously. Such machines exploit data level parallelism, but not concurrency: there are simultaneous (parallel) computations, but only a single process (instruction) at a given moment.

在 OpenMP 中您可以使用 SIMD 指令,即:

#pragma omp simd
for ( i = 0; i < n; i++ )
    a[i] = b[i] * c[i];

关于SISD,从Wikipedia可以看到:

In computing, SISD (single instruction stream, single data stream) is a computer architecture in which a single uni-core processor executes a single instruction stream, to operate on data stored in a single memory.

这不是关于代码的这么多,而是代码将如何在底层架构中执行。反映这个概念的代码是:

for(int i = 0; i < N; i++)
   a[i]++;

关于MISD,从Wikipedia可以读到:

In computing, MISD (multiple instruction, single data) is a type of parallel computing architecture where many functional units perform different operations on the same data. Pipeline architectures belong to this type, though a purist might say that the data is different after processing by each stage in the pipeline.

for(int i = 0; i < N; i++)
   a[i] = 10 * a[i] + a[i] / 2;

关于MIMD,从Wikipedia可以读到:

In computing, MIMD (multiple instruction, multiple data) is a technique employed to achieve parallelism. Machines using MIMD have a number of processors that function asynchronously and independently.

为此,您可以拥有一个包含两个进程的 MPI 应用程序,其中每个进程执行两个不同的应用程序。