6 Cloud Programming Models And Parallelization

Cloud Computing · Unit 6

Cloud Programming Models and Parallelization

Exam-focused notes for Cloud Programming Models and Parallelization (Cloud Computing, BIT408): what the TU syllabus asks and how it has actually been tested, with 9 solved past questions from this unit.

Cloud Programming Models and Parallelization in short

Large cloud jobs must be split into parts that run at the same time on many machines. This chapter covers two programming styles, threads and tasks. It also covers MapReduce, the standard way to process very large data sets in parallel.

Cloud Programming Models and Parallelization: notes

Thread programming in cloud

A thread is the smallest unit of work that an operating system can schedule. One program (process) can have many threads, and they share the same memory. Thread programming means writing a program so that several threads run at once, so the work finishes sooner.

In the cloud, a VM may have several CPU cores. Threads let one application use all of them.

Main points:

  • Threads share memory, so they exchange data easily.
  • Shared data needs synchronization, such as locks, to avoid wrong results (race conditions).
  • Too many threads waste time on switching between them.
  • Threads normally work inside one machine, so they scale only as far as one VM.
class Worker extends Thread {
    int start, end;
    long sum = 0;
    Worker(int s, int e) { start = s; end = e; }
    public void run() {
        for (int i = start; i <= end; i++) sum += i;
    }
}
// Two threads add 1..500 and 501..1000, then the results are combined.

Task programming in cloud

A task is a unit of work that is defined by what it must do, not by how it is run. The programmer divides the job into tasks. A runtime or scheduler then decides which thread or machine runs each task and when.

  • Tasks can be independent, or can depend on other tasks.
  • A task library or cloud framework handles scheduling, retries and load balancing.
  • A failed task can be run again on another machine.
  • Tasks scale across many machines, not only across cores of one machine.

Examples: .NET Task Parallel Library, Java executor services, and cloud job queues where workers pick tasks from a queue.

Comparison between thread and task programming

PointThread programmingTask programming
UnitThread, a unit of executionTask, a unit of work
ControlProgrammer creates and manages threadsRuntime schedules the tasks
LevelLow levelHigher level
ScaleUsually one machineCan spread over many machines
Failure handlingProgrammer must handle itFailed tasks can be retried
DifficultyHarder, with locks and racesEasier to write and maintain
Resource useMany threads can slow the systemScheduler uses resources wisely

In short, threads say how to run, and tasks say what to run.

What this unit covers

  • Thread programming in cloud
  • Task programming in cloud
  • Comparison between thread and task programming
  • MapReduce framework and model
  • MapReduce configuration parameters
  • MapReduce parallel efficiency
  • Parallelization implementation in cloud
  • MapReduce examples and applications

Thread programming in cloud

2082 · 10 marks

What is thread programming? How can map reducing is used in cloud programming model? Support your answer with suitable example.[10]

Show solved answer

Model Answer: Thread Programming and MapReduce in Cloud Computing

Part 1: Thread Programming (3-4 marks)

Definition

Thread programming is a concurrent programming model where multiple threads of execution run within a single process, sharing the same memory space and resources. A thread is the smallest unit of execution that can be scheduled independently by the operating system.

Key Characteristics

  • Lightweight: Threads are lighter than processes; creating and context-switching between threads is faster
  • Shared Memory: All threads within a process share the same heap and global variables
  • Independent Execution: Each thread has its own stack, program counter, and local variables
  • Concurrent Execution: Multiple threads can execute simultaneously on multi-core systems

Basic Thread Operations

  1. Thread Creation: Instantiate and start a new thread
  2. Thread Synchronization: Use locks, semaphores, and monitors to coordinate access to shared resources
  3. Thread Termination: Gracefully end thread execution
  4. Thread Communication: Exchange data between threads safely

Advantages

  • Improved responsiveness and interactivity
  • Better resource utilization
  • Simplified program structure for concurrent tasks

Part 2: MapReduce in Cloud Programming Model (5-6 marks)

What is MapReduce?

MapReduce is a distributed computing framework for processing large datasets across clusters of computers in a cloud environment. It follows a divide-and-conquer approach with two main phases: Map and Reduce.

How MapReduce Works

Phase 1: Map Phase

  • Input data is divided into independent chunks
  • Each chunk is processed by a mapper function in parallel
  • Mapper transforms input into intermediate key-value pairs: (key, value)
  • Output: List<(key, value)>

Phase 2: Reduce Phase

  • Intermediate key-value pairs are grouped by key
  • All values for the same key are sent to a single reducer
  • Reducer aggregates/combines values for each key
  • Output: Final result List<(key, final_value)>

Advantages in Cloud Computing

  • Scalability: Processes petabytes of data across thousands of nodes
  • Fault Tolerance: Automatic re-execution of failed tasks
  • Data Locality: Computation moves to data, reducing network traffic
  • Parallelism: Massive parallel processing capability

Practical Example: Word Count

Problem

Count the frequency of each word in a large collection of documents.

Solution Using MapReduce

Input Data:

Document 1: "cloud computing cloud"
Document 2: "cloud programming"
Document 3: "computing programming"

Map Phase:

Mapper 1 processes Doc 1:
  Input: "cloud computing cloud"
  Output: (cloud, 1), (computing, 1), (cloud, 1)

Mapper 2 processes Doc 2:
  Input: "cloud programming"
  Output: (cloud, 1), (programming, 1)

Mapper 3 processes Doc 3:
  Input: "computing programming"
  Output: (computing, 1), (programming, 1)

Shuffle and Sort Phase:

(cloud, [1, 1, 1])
(computing, [1, 1])
(programming, [1, 1])

Reduce Phase:

Reducer 1: (cloud, [1, 1, 1]) → (cloud, 3)
Reducer 2: (computing, [1, 1]) → (computing, 2)
Reducer 3: (programming, [1, 1]) → (programming, 2)

Final Output:

cloud: 3
computing: 2
programming: 2

Why MapReduce is Effective Here

  • Large documents are processed in parallel by multiple mappers
  • Network traffic is minimized by processing data locally
  • Reducers efficiently aggregate counts across the entire dataset
  • Fault tolerance ensures completion even if nodes fail

Conclusion

Thread programming enables concurrent execution within a single process, while MapReduce provides a distributed framework for processing massive datasets across cloud clusters. Together, they represent different levels of parallelism: thread-level (within a machine) and data-level (across machines).

Open this answer on its own page →

MapReduce framework and model

2081 · 5 marks

Explain Map Reduce in brief with suitable example. [5]

MapReduce is a programming model and processing technique for distributed computing that processes large datasets in parallel across a cluster of computers. It breaks down a computational problem into smaller sub-problems, processes them independently, and then combines the results. MapReduce con...

Open this answer on its own page →

0 · 5 marks

Explain about map reduce with an example. [5]

MapReduce is a programming model and processing technique used for distributed computing on large datasets across a cluster of computers. It breaks down complex data processing tasks into smaller, manageable pieces that can be processed in parallel. MapReduce consists of two main phases: - Takes ...

Open this answer on its own page →

Comparison between thread and task programming

2081 · 5 marks

Differentiate between Thread Programming and Task Programming. [5]

Aspect Thread Programming Task Programming --------------------------------------------- Unit of Execution Explicit threads are created and managed by the programmer Tasks are higher-level abstractions; threads are managed by a scheduler/runtime Abstraction Level Lower-level; direct control over ...

Open this answer on its own page →

2080 · 5 marks

What is the difference between thread programming and task programming in cloud computing? Describe. [5]

Show solved answer

Model Answer: Thread Programming vs Task Programming in Cloud Computing

Definition and Core Difference

Thread Programming and Task Programming represent two different paradigms for concurrent execution in cloud computing environments:

Thread Programming

  • Definition: A programming model where multiple threads of execution run within a single process, sharing the same memory space
  • Characteristics:
    • Threads are lightweight execution units
    • Share heap memory and global variables
    • Require explicit synchronization mechanisms (locks, semaphores, mutexes)
    • Lower overhead for creation and context switching
    • More prone to race conditions and deadlocks if not carefully managed

Task Programming

  • Definition: A higher-level abstraction where work is divided into independent tasks that can be executed concurrently without explicit thread management
  • Characteristics:
    • Tasks are logical units of work (often independent)
    • Managed by a task scheduler or runtime system
    • Minimal or no shared state between tasks
    • Automatic load balancing and resource allocation
    • Easier to reason about and debug

Key Differences

AspectThread ProgrammingTask Programming
Abstraction LevelLow-levelHigh-level
Memory ModelShared memoryIsolated/message-passing
SynchronizationManual (locks, etc.)Automatic
ScalabilityLimited by thread overheadBetter for cloud scale
ComplexityHigher (concurrency bugs)Lower (simpler logic)
Cloud SuitabilityLess idealMore ideal

Conclusion

Task programming is generally preferred in cloud computing because it abstracts away low-level threading complexities, provides better scalability, and reduces synchronization errors, making it more suitable for distributed, large-scale cloud applications.

Open this answer on its own page →

0 · 5 marks

Compare between thread and task. [5]

Thread: A thread is the smallest unit of execution within a process. It is a lightweight process that shares the same memory space with other threads in the same process. Task: A task is a higher-level abstraction that represents a unit of work to be executed. In modern programming (especially as...

Open this answer on its own page →

MapReduce configuration parameters

2080 · 5 marks

What are the main configuration parameters that are specified in MapReduce? Explain. [5]

MapReduce configuration parameters are settings that control the behavior and performance of MapReduce jobs. The main configuration parameters are: - mapreduce.job.name: Specifies the name of the MapReduce job for identification and monitoring purposes. - mapreduce.job.queue.name: Defines which q...

Open this answer on its own page →

MapReduce parallel efficiency

2080 · 5 marks

Explain parallel efficiency of MapReduce. [5]

Parallel efficiency (E) measures how effectively a parallel system utilizes its computing resources compared to an ideal scenario. For MapReduce, it indicates how well the framework scales as more nodes are added to the cluster. E = S / P Where: - S = Speedup (ratio of sequential time to parallel...

Open this answer on its own page →

Parallelization implementation in cloud

0 · 5 marks

How do you implement parallelization in cloud computing? Explain. [5]

Parallelization in cloud computing refers to the simultaneous execution of multiple tasks or processes across distributed cloud resources to improve performance, reduce execution time, and increase throughput. - Divide large datasets into smaller chunks - Process each chunk simultaneously on diff...

Open this answer on its own page →