0% found this document useful (0 votes)
33 views15 pages

HPC LA Report-1

Uploaded by

amoghak369
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views15 pages

HPC LA Report-1

Uploaded by

amoghak369
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

HIGH PERFORMANCE COMPUTING LA2 REPORT

on

Parallel Computation of Age Statistics Using MPI for School Grade


Simulation
Submitted in partial fulfilment of the requirement for the award of Degree of

Bachelor of Engineering
in
Computer Science and Engineering
Submitted by:
Darshan R. M. 1NT21CS058

Under the Guidance of


Mr. Deepak R
Assistant Professor, Dept. of CS&E, NMIT

Department of Computer Science and Engineering


(Accredited by NBA Tier-1)
2024-2025
NITTE MEENAKSHI INSTITUTE OF TECHNOLOGY
(AN AUTONOMOUS INSTITUTION, AFFILIATED TO VISVESVARAYA TECHNOLOGICAL UNIVERSITY, BELGAUM
, APPROVED BY AICTE & GOVT.OF KARNATAKA)

Department of Computer Science and Engineering


(Accredited by NBA Tier-1)

CERTIFICATE

This is to certify that the Parallel Computation of Age Statistics Using MPI for School Grade
Simulation (High Performance Computing Learning Assessment 2) is an authentic work carried
out by Darshan R. M. (1NT21CS058) Bonafide student of Nitte Meenakshi Instituteof
Technology, Bangalore in partial fulfilment for the award of the degree of Bachelor of
Engineering in COMPUTER SCIENCE AND ENGINEERING of Visvesvaraya Technological
University, Belgavi during the academic year 2024-25. It is certified that all corrections and
suggestions indicated during the internal assessment has been incorporated inthe report. This
learning assessment has been approved as it satisfies the academic requirement in respect of
learning assessment presented for the said degree.

Faculty Co-ordinator

Mr. Deepak R
Assistant Professor,
Dept. of CSE, NMIT Bangalore
DECLARATION
I hereby declare that

(i) The learning assessment is my original work


(ii) This learning assessment has not been submitted for the award of any degree or examination
at any other university/College/Institute.
(iii) This learning assessment does not contain other persons’ data, pictures, graphs or other
information, unless specifically acknowledged as being sourced from other persons.
(iv) This learning assessment does not contain other persons’ writing, unless specifically
acknowledged as being sourced from other researchers. Where other written sources have been
quoted, then:
a) their words have been re-written but the general information attributed to them has been
referenced;
b) where their exact words have been used, their writing has been placed inside quotation
marks, and referenced.
(v) This learning assessment does not contain text, graphics or tables copied and pasted from the
Internet, unless specifically acknowledged, and the source being detailed in the thesis and in
the References sections.

NAME USN Signature

DARSHAN R. M. 1NT21CS058

Date: 20/12/2024
ACKNOWLEDGEMENT

The satisfaction and euphoria that accompany the successful completion of any task would be
incomplete without the mention of the people who made it possible, whose constant guidance and
encouragement crowned our effort with success. I express my sincere gratitude to our Principal
Dr. H. C. Nagaraj, Nitte Meenakshi Institute of Technology for providing facilities.

I wish to thank our HoD, Dr. S Meenakshi Sundaram. for the excellent environment created to
further educational growth in our college. I also thank him for the invaluable guidance provided
which has helped in the creation of a better learning assessment.

I hereby like to thank our Mr.Deepak R, Assistant Professor, Department of Computer Science &
Engineering on his periodic inspection, time to time evaluation of the learning assessment and helpto
bring the learning assessment to the present form.

I also thank all our friends, teaching and non-teaching staff at NMIT, Bangalore, for all the direct
and indirect help provided in the completion of the learning assessment.

NAME USN Signature

DARSHAN R. M. 1NT21CS058

Date: 20/12/2024
ABSTRACT

This project explores the use of the Message Passing Interface (MPI) to simulate the collection and
computation of age statistics in a school setting. The school consists of three grades (PreKG, LKG, UKG),
each with five sections, and each section has ten students. The simulation involves parallel computation,
where each section is represented as an independent process to collect age data.

The program utilizes random number generation to simulate the ages of students and employs MPI's
reduction functions to calculate the minimum age, maximum age, and average age for each section, grade,
and the entire school. This approach demonstrates the efficiency of distributed computing in solving real-
world problems by leveraging parallel processing and aggregation techniques.

Additionally, the implementation emphasizes the scalability and adaptability of the MPI framework. By
distributing tasks across multiple processes, the program efficiently handles large datasets, reducing
computational time and resource usage. The design also provides insights into the importance of parallel
programming in modern applications, making it an effective solution for similar large-scale statistical
computations.
TABLE OF CONTENTS

Sl. NO Title Page No


1. Introduction 1-2

Background
Brief History of Technology/Concept
Applications
Problem Statement
Primary Objectives
2. Implementation 3-6

Methodology
Flow Diagram
Code
3. Result Analysis 7

4. Conclusion 8
LIST OF FIGURES

FIGURE PAGE
DESCRIPTION
NUMBER NUMBER
1 Program Flow 4
2 Output of Code Execution 7
CHAPTER 1
INTRODUCTION
Background
In modern distributed systems, efficient communication and data aggregation are critical
for the seamless operation of geographically dispersed units. Restaurant chains, which
handle vast amounts of transactional and sales data, benefit significantly from parallel
computing techniques to optimize operations, reduce communication overhead, and
improve decision-making. OpenMPI (Open Message Passing Interface) facilitates robust,
scalable communication for such systems, enabling real-time data exchange and processing
across multiple nodes.

Brief History of Technology/Concept


Parallel Distributed computing emerged in the mid-20th century to address the need for
faster and more efficient data processing by leveraging multiple interconnected computing
systems. The Message Passing Interface (MPI) was standardized in 1994, providing a
portable and scalable framework for parallel computing. OpenMPI, introduced in 2004,
extended MPI's capabilities by incorporating advanced features for high-performance
computing and ease of integration across platforms.

In industries like hospitality, where rapid data collection, aggregation, and dissemination
are critical, MPI's message-passing paradigm ensures minimal latency and high data
consistency. Restaurant management systems, particularly those distributed across
locations, use such technologies for sales monitoring, resource allocation, and performance
optimization.

Applications
The concepts and technologies used in OpenMPI for distributed communication extend
to various domains, including:

• Restaurant Chain Management: Real-time data collection, aggregation, and


dissemination of sales metrics to optimize operations.

1
• Retail and E-Commerce: Synchronizing inventory and sales data across
distributed warehouses and stores.
• Supply Chain Optimization: Facilitating efficient communication between
different nodes in the supply chain for real-time updates.
• IoT Systems: Collecting and processing sensor data from geographically
distributed devices for centralized analysis.

Problem Statement
A school has five sections for each grade and they have three grades (PreKG, LKG and
UKG). They send a teacher to each section to get the information about the age of each
child in the section. Assume that there are ten students in each section. Assuming each
teacher is simulated as a thread use the MPI-Reduction function to determine the
Minimum age, the Maximum age and the Average age for each section, each grade and
for the whole school. Use random numbers for generating the age of the children.

Primary Objectives
The primary objectives of this project are as follows:
1. Simulate a School's Data Structure: Represent the school's organization with three
grades (PreKG, LKG, UKG), five sections per grade, and ten students per section.
2. Generate Random Age Data: Create random ages for students in each section to
simulate real-world data.
3. Utilize MPI for Parallel Computing: Employ MPI to assign each section as an
independent process for parallel computation.
4. Calculate Local Statistics:
5. Compute the minimum age, maximum age, and average age for each section.
6. Aggregate Global Statistics:
7. Use MPI reduction operations to calculate the minimum, maximum, and average ages
for each grade and the entire school.
8. Demonstrate Scalability:
9. Showcase the ability to efficiently handle computations for larger datasets using
distributed processes.

2
Chapter 2
IMPLEMENTATION

Methodology
The age statistics computation system for a simulated school was implemented using MPI to perform
distributed parallel processing. The following steps outline the methodology:

Step 1: Initialization
• Each section of the school is modeled as an MPI process, where every process simulates a section
of one grade.
• The MPI environment is initialized using MPI_Init, and the rank and size of each process are
determined using MPI_Comm_rank and MPI_Comm_size.

Step 2: Data Generation


• Each process generates random ages for 10 students in its section using a predefined range (e.g.,
3–8 years).

Step 3: Local Statistics Calculation


• Each process computes:
o Minimum Age: The smallest age value in the section.
o Maximum Age: The largest age value in the section.
o Sum of Ages: Used to calculate the average age.

Step 4: Global Data Aggregation


• All processes send their local statistics (min, max, and sum) to rank 0 using MPI_Reduce:
o MPI_MIN: To find the global minimum age.
o MPI_MAX: To find the global maximum age.
o MPI_SUM: To aggregate the sum of ages for average computation.

Step 5: Result Computation


• The root process (rank 0) computes:
o The average age for each grade and the whole school by dividing the total sum by the
number of students.

Step 6: Synchronization and Termination


• All processes are synchronized using MPI_Barrier to ensure consistent results before termination.
• The MPI environment is finalized with MPI_Finalize.

Step 7: Output Results


• The root process (rank 0) outputs:
o Minimum, maximum, and average age for each section.
o Aggregated statistics for each grade.
o Overall statistics for the entire school.
• Results are displayed in a consolidated format for analysis.
3
Flow Diagram

Figure 1. Program Flow


4
Code

#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define STUDENTS_PER_SECTION 10
#define SECTIONS 5
#define GRADES 3
#define MIN_AGE 3
#define MAX_AGE 8

int main(int argc, char* argv[]) {


int rank, size;
int local_ages[STUDENTS_PER_SECTION];
int local_min, local_max, local_sum;
int global_min, global_max, global_sum;
double start_time, end_time;

// Initialize MPI
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

if (size != GRADES * SECTIONS) {


if (rank == 0) {
printf("This program requires %d processes.\n", GRADES * SECTIONS);
}
MPI_Finalize();
return -1;
}

// Seed random number generator


srand(time(NULL) + rank);

// Generate random ages for the section


printf("Section %d (Process %d): ", rank % SECTIONS + 1, rank);
for (int i = 0; i < STUDENTS_PER_SECTION; i++) {
local_ages[i] = MIN_AGE + rand() % (MAX_AGE - MIN_AGE + 1);
printf("%d ", local_ages[i]);
}
printf("\n");

// Compute local statistics


local_min = local_max = local_ages[0];
local_sum = 0;
for (int i = 0; i < STUDENTS_PER_SECTION; i++) {
if (local_ages[i] < local_min) local_min = local_ages[i];
if (local_ages[i] > local_max) local_max = local_ages[i];
5
local_sum += local_ages[i];
}

// Start measuring time


if (rank == 0) {
start_time = MPI_Wtime();
}

// Perform reduction to calculate global min, max, and sum


MPI_Reduce(&local_min, &global_min, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD);
MPI_Reduce(&local_max, &global_max, 1, MPI_INT, MPI_MAX, 0, MPI_COMM_WORLD);
MPI_Reduce(&local_sum, &global_sum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);

// Stop measuring time


if (rank == 0) {
end_time = MPI_Wtime();
}

// Display results on the root process


if (rank == 0) {
int total_students = STUDENTS_PER_SECTION * size;
double average_age = (double)global_sum / total_students;

printf("\n--- School Age Statistics ---\n");


printf("Minimum Age: %d\n", global_min);
printf("Maximum Age: %d\n", global_max);
printf("Average Age: %.2f\n", average_age);

// Execution time
printf("Execution Time: %.6f seconds\n", end_time - start_time);
}

// Finalize MPI
MPI_Finalize();
return 0;
}

6
CHAPTER 3
RESULT ANALYSIS

Figure 2. Output of code execution

7
CHAPTER 4
CONCLUSION

The MPI-based solution efficiently simulates the collection of age data across a school with three grades
and five sections per grade, leveraging parallel processing for faster computation. Each section operates as
an independent MPI process, enabling concurrent generation of student age data and local statistics
calculation.

By utilizing MPI_Reduce, the program aggregates local data from all processes to compute global
statistics, such as minimum age, maximum age, and average age, ensuring accurate results at the
school level.

The design guarantees scalability and efficiency, with processes working independently yet
collaborating to achieve a unified result. The solution highlights the power of MPI in handling real-
world distributed computing problems effectively. With proper configuration and random age
generation, the implementation successfully meets the problem requirements for statistical analysis of
the students' age data.

You might also like