Site Tools


parallel-computing

Table of Contents

Parallel computing

Parallel computing is a computational model where work is broken into parts that execute simultaneously across multiple processors, cores, or machines. Modern CPUs gain performance through additional cores rather than clock speed increases, so exploiting parallelism is essential for performance.

Amdahl's law shows the sequential fraction limits speedup; Gustafson's law shows that scaling problem size with hardware yields near-linear speedup.

Example

This example shows a simple parallel computation using OpenMP.

// compile: gcc -fopenmp -o parallel parallel.c
// run: ./parallel
// description: parallel loop computing array sum
 
#include <omp.h>
#include <stdio.h>
 
int main() {
    int arr[100];
    for (int i = 0; i < 100; i++) arr[i] = i;
 
    int sum = 0;
#pragma omp parallel for reduction(+:sum)
    for (int i = 0; i < 100; i++) {
        sum += arr[i];
    }
 
    printf("Sum: %d\n", sum);
    return 0;
}
parallel-computing.md · Last modified: by 127.0.0.1