Distributed Programming: Two Traditional Communication Mechanism

本文探讨了共享内存和消息传递两种并行编程模型。共享内存模型中,任务通过共享内存区域交换数据,需使用同步机制如信号量、锁和屏障来协调任务。消息传递模型则通过显式消息发送接收数据,不需显式同步,各任务拥有独立内存空间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

shared memory vs message passing

Shared Memory

Key Abstraction:
  • Every task can access any location in an application’s distributed memory space. as is the case with threads in a single process, where all threads share the process address space
Feature
  • Tasks exchange data implicitly via sharing and not by explicitly sending and receiving messages.

  • The shared-memory model, consequently, supports synchronisation mechanisms that distributed programs must use to control the order in which various tasks can perform read/write operations. This goal typically can be achieved using semaphores, locks, and/or barriers.

Synchronisation Mechanism
1. Semaphore

A semaphore is a point-to-point synchronization mechanism that involves two parallel/distributed tasks. Semaphores use two operations: post and wait. The post operation acts like depositing a token, signaling that data has been produced. The wait operation blocks until signaled by the post operation that it can proceed to consume data.

2. Locks

Locks protect critical sections, which are regions that only one task can access (typically write) at a time. Locks involve two operations, lock and unlock, for acquiring and releasing a lock associated with a critical section. A lock can be held by only one task at a time, and other tasks cannot acquire it until released.

3. Barrier

Last, a barrier defines a point beyond which a task is not allowed to proceed until every other task reaches that point.

Example
  • DSM-OpenMP

The Message-Passing Programming Model

Key Abstraction:
  • Resembles processes that, unlike threads, each maintain a private memory space.
Feature
  • To send and receive data via explicit messages, this model incurs communication overheads
  • No explicit synchronization is needed
  • The interacting tasks require no illusion of a single, shared address space.
Example:
  • Message passing interface (MPI)
  • Implementation: MPICH

Comparison

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值