Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Approaches to Parallel Programming

Lesson 21 of 30 in the free Cloud Computing notes on Siksha Sarovar, written by Rohit Jangra.

Approaches to Parallel Programming

Parallel hardware is useless without programming models that let developers express parallelism. Four major paradigms cover the landscape, each suited to different hardware and problem structures.

Taxonomy of Approaches

1. Shared Memory Programming

All threads access a common address space. Synchronization (mutexes, semaphores, barriers) prevents race conditions.

  • OpenMP: Compiler directives for C/C++/Fortran. Add #pragma omp parallel for before a loop and the compiler parallelizes it across cores. Used in scientific computing.
  • pthreads: Low-level POSIX thread API. Fine-grained control, high complexity.
  • Java synchronized: Language-level shared memory concurrency.

Pros: Simple data sharing, low latency communication Cons: Limited to one machine; race conditions and deadlocks are hard to debug

2. Message Passing

Processes have private memory and communicate by explicitly sending and receiving messages. No shared state.

  • MPI (Message Passing Interface): The standard for HPC. Programs run as N independent processes; data is exchanged via MPI_Send / MPI_Recv. Used on supercomputers and AWS HPC clusters running thousands of nodes.
  • Actor model (Erlang, Akka): Each actor has a mailbox; actors communicate asynchronously.

Pros: Scales to thousands of nodes; no race conditions (no shared state) Cons: Programmer must manage all data movement explicitly

3. Data Parallel

Apply the same operation to many data elements simultaneously. Maps directly to SIMD hardware (GPUs, vector units).

  • CUDA: NVIDIA's programming model for GPUs. A kernel function runs on thousands of GPU threads simultaneously, each processing a different data element.
  • OpenCL: Vendor-neutral alternative (works on AMD, Intel, NVIDIA).
  • CPU intrinsics (AVX-512): Explicit SIMD instructions in C/C++.

Use case: Deep learning (matrix multiply), image processing, physics simulations.

4. Task Parallel

Decompose the program into independent tasks that can run in any order. A runtime scheduler assigns tasks to available threads/cores.

  • Intel TBB (Threading Building Blocks): C++ library with parallel_for, pipeline, task_group.
  • Go goroutines: Lightweight green threads with channel-based communication.
  • AWS Lambda: Serverless task parallelism at cloud scale — each invocation is an independent task.

Comparison

ParadigmMemory ModelScales ToBest For
Shared MemorySharedOne machine (many cores)Loop parallelism, scientific codes
Message PassingPrivateThousands of nodesHPC, distributed ML
Data ParallelPrivate (GPU)One GPU (thousands of cores)Deep learning, graphics
Task ParallelEitherVariesIrregular workloads, pipelines

Cloud Mapping

Cloud ServiceParadigm
AWS LambdaTask parallel (serverless)
AWS ParallelCluster + MPIMessage passing
Google TPU PodsData parallel
Azure BatchTask parallel