Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
8 views
5 pages
S24 PDC Mid Exam Solution
Parallel And distrubuted computing
Uploaded by
abbastayyaba417
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save S24 PDC Mid Exam Solution For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
8 views
5 pages
S24 PDC Mid Exam Solution
Parallel And distrubuted computing
Uploaded by
abbastayyaba417
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save S24 PDC Mid Exam Solution For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 5
Search
Fullscreen
Clulbersity of Central Wunjab Faculty oF tofupmuation Technolugy Parattel ang Distributed Computing Mid Terms Sprit Registration Nomne=___——__ ‘Duration: Seat 1362 polatsy at serv of cache local Assure 10 Moe Order is achievable in ye fallowing code tod how would you obtain it? erooty fer he aay.) Tor Gt: jem; jay For (let; om ies ALLL = AC LOT + ayy, Solution: The type of cache locality that és achievable ia the provided code is spatial locality. Spatial Jocality refers t0 the tse Of data elements within relatively close storage lucations. The given code accesses actay elements in a eolumnemajar order dve 10 the arrangement of the Loop indices. Tw improve spatial locality and parentially enkance cache performances. you should switelt the onder of the loops to secess the elements in a row-majar order: for (=O: 1g tes for b=) < Milla) = Abii) * BULL by Wrtea cade using » loop mevich cout be pacallesed? nie Solution: An example of a loop that cannot be | paralized effectively th one dist ‘The code caleulates the sum of rumbers contains depentlencics from ane iteration fave} ton wsing «Loup to the next, such as calculating the In each iterstion. the current value of i Fibonacci sequence: is added to the sum, 7. . ©) This calculation depends on the previous tt Ont) Value of sum, For example, to calculate the for int d= 2; 1< m3 9) ( sum of: J the sum of the first fib2 = fibl + fib; fit = fit: fibt = fib’ using namespace st:int maing) | sun > i: Dependent an previ value int n> 10:// Number af elements fee int sum © 0 t Loop to caleulate the sum of clements SSeS ie Se Sui Sele from 1 to n (serial) telumn O; for (int i ple) ‘ 2 (3:2 paints) ‘SMG of a progratn’s execution time aecurs inside a lvop thst ea.a he executed in paralel and ress 40% in Serial 3) What s the maximum speedup we should expect from a parallel version of the progr executiny of core CPU hb) Ifwe wanted toachleve 4 time speedup how may processing tinity will ke required. is it prnsible gain such speedip? Ps the proportion of the progeam that can be parallelizer! (0,6 in this case), Nis the number af processors (@ cores in this case} Sphinn bts. b) Achieving 4s Speedup: This speedup can't be achieved, according to. amdeht's lav; It can’t ga beyond 2 The N value should be negative instead of 6 it should Ge The answer was "this valut C201 be achieved because if we put Ninf we will get lesser Value then &; 18 pants) a The army must be declared and initialized jn the main thread. You may initial rand) fumetion. =include
include
sinelude
#define ARRAY_SIZE 1000. int arr| ARRAY_SIZE]; // Array to store elements (1000 elements) "int sum = 0; // Global variable to store the final sum /! Mutex for thread synchronization pthread_mutex_t muten / Thread function to calculate partial sum void *sum_array(void *arg) { int start = *(int *)arg: #f Get starting index from argument int end = start +(ARRAY_SIZE/N); — // Calculate ending index int partial_sum = 0; / Variable for partial sum for (int i = start; i < end; i++) { partial_sum += arr[i); # Add element to partial sum ‘ ‘ pthread_mutex_lock(&mutex); /! Acquire lock for shared variable sum += partial_sum: 4 Add partial sum to global sum pthread_mutex_unlock(&mutex ——_// Release lock after modification free(arg); // Free memory allocated for start_index return NULL; > s int main(int arge, char *arev[])Purge | prinut("Usay
\n", argy]O)); return 1; evi) sranditime( NULL): ARRAY_SIZE; i++) | int N = atoil Get number of threads from command line for (inti = 05 arrfi] = rand() % 100; // Initialize array with random values puhread_t threads[N}: / Array to store thread handles pthread_mutes_init(&mutex, NULL): // Initialize mutex for Ginti=0;1
You might also like
Lecture 14 Firewall
PDF
No ratings yet
Lecture 14 Firewall
46 pages
Sample Report
PDF
No ratings yet
Sample Report
7 pages
CSE524sp10 01
PDF
No ratings yet
CSE524sp10 01
62 pages
CS4230 Parallel Programming Introduction To Parallel Algorithms
PDF
No ratings yet
CS4230 Parallel Programming Introduction To Parallel Algorithms
25 pages
Lab 07 - Programming Threads
PDF
No ratings yet
Lab 07 - Programming Threads
9 pages
Assignment 1
PDF
No ratings yet
Assignment 1
5 pages
Ex No 3
PDF
No ratings yet
Ex No 3
3 pages
Lab10 C
PDF
No ratings yet
Lab10 C
2 pages
Dixit Abhishek
PDF
No ratings yet
Dixit Abhishek
54 pages
Operating System - Lab 4
PDF
No ratings yet
Operating System - Lab 4
7 pages
02 Multicore
PDF
No ratings yet
02 Multicore
66 pages
115 Tip Pthreads
PDF
No ratings yet
115 Tip Pthreads
4 pages
Lab 11 Os UVT
PDF
No ratings yet
Lab 11 Os UVT
2 pages
8th Lab Program
PDF
No ratings yet
8th Lab Program
9 pages
410A Week 5
PDF
No ratings yet
410A Week 5
23 pages
Mutex
PDF
No ratings yet
Mutex
2 pages
202ucs19 Hpc-Lab Exp2
PDF
No ratings yet
202ucs19 Hpc-Lab Exp2
3 pages
Unit 3 ConcurrentProgramminng Bryant
PDF
No ratings yet
Unit 3 ConcurrentProgramminng Bryant
18 pages
Book
PDF
No ratings yet
Book
10 pages
Lab Programs
PDF
No ratings yet
Lab Programs
18 pages
410A Week 6
PDF
No ratings yet
410A Week 6
31 pages
PDC LAB Experiment 2
PDF
No ratings yet
PDC LAB Experiment 2
12 pages
POS Manual
PDF
No ratings yet
POS Manual
31 pages
操作系统课程作业 4
PDF
No ratings yet
操作系统课程作业 4
3 pages
Pes1ug24cs838 Vikasks PDF
PDF
No ratings yet
Pes1ug24cs838 Vikasks PDF
5 pages
4 Multi-Threading
PDF
No ratings yet
4 Multi-Threading
34 pages
Swapnil PDC
PDF
No ratings yet
Swapnil PDC
43 pages
Lab01 PDF
PDF
No ratings yet
Lab01 PDF
5 pages
Pes1ug24cs838 Vikasks
PDF
No ratings yet
Pes1ug24cs838 Vikasks
5 pages
Shadab - DS Lab File
PDF
No ratings yet
Shadab - DS Lab File
17 pages
資工
PDF
No ratings yet
資工
3 pages
Computer Programming Lab Manual
PDF
No ratings yet
Computer Programming Lab Manual
103 pages
Lab4 22bps1216
PDF
No ratings yet
Lab4 22bps1216
7 pages
Recursion & Pointers: Instructor: Alvin R. Lebeck
PDF
No ratings yet
Recursion & Pointers: Instructor: Alvin R. Lebeck
6 pages
Attachment 1 27
PDF
No ratings yet
Attachment 1 27
6 pages
Os Lab 11 I200958
PDF
No ratings yet
Os Lab 11 I200958
11 pages
CSE2005-Operating Systems Lab Assessment-2: Questions 1
PDF
No ratings yet
CSE2005-Operating Systems Lab Assessment-2: Questions 1
29 pages
C Lab Manuals
PDF
No ratings yet
C Lab Manuals
98 pages
Final
PDF
No ratings yet
Final
4 pages
Lab 04
PDF
No ratings yet
Lab 04
2 pages
Week 3
PDF
No ratings yet
Week 3
14 pages
Written Asst2
PDF
No ratings yet
Written Asst2
27 pages
Lab 2 Threads
PDF
No ratings yet
Lab 2 Threads
6 pages
Code - Example 2
PDF
No ratings yet
Code - Example 2
3 pages
08 Systems Programming-Concurrent Programming
PDF
No ratings yet
08 Systems Programming-Concurrent Programming
61 pages
Lab File: Distributed System Lab (RCS-751)
PDF
No ratings yet
Lab File: Distributed System Lab (RCS-751)
30 pages
Ex - Lab5 - EN
PDF
No ratings yet
Ex - Lab5 - EN
2 pages
18-Assignment 1 - Solution
PDF
No ratings yet
18-Assignment 1 - Solution
12 pages
NCS 751 Lab Manual
PDF
No ratings yet
NCS 751 Lab Manual
16 pages
C-Programming and Data Structures Lab Manual
PDF
100% (5)
C-Programming and Data Structures Lab Manual
251 pages
Thread Programs Practice
PDF
No ratings yet
Thread Programs Practice
2 pages
Pthreads Mod
PDF
No ratings yet
Pthreads Mod
110 pages
06 Decision Tables - Done
PDF
No ratings yet
06 Decision Tables - Done
27 pages
Topic 6A 2024
PDF
No ratings yet
Topic 6A 2024
55 pages
Numerical Solutions
PDF
No ratings yet
Numerical Solutions
2 pages
02 Testing Process - Done
PDF
No ratings yet
02 Testing Process - Done
24 pages
05 Boundary Value Analysis - Done
PDF
No ratings yet
05 Boundary Value Analysis - Done
16 pages
01a SQA - Done
PDF
No ratings yet
01a SQA - Done
28 pages
Lecture 10 DB Security
PDF
No ratings yet
Lecture 10 DB Security
33 pages
Lecture 13 ACL
PDF
No ratings yet
Lecture 13 ACL
19 pages
Lecture 11 Malware
PDF
No ratings yet
Lecture 11 Malware
17 pages
Lexical Analyzer
PDF
No ratings yet
Lexical Analyzer
16 pages
Lecture-12 SoftwareSecurity
PDF
No ratings yet
Lecture-12 SoftwareSecurity
22 pages
Introduction To Natural Language Processing
PDF
No ratings yet
Introduction To Natural Language Processing
31 pages
Intro To NLP Course Outline (Fall-2024)
PDF
No ratings yet
Intro To NLP Course Outline (Fall-2024)
4 pages
Parser and CFG
PDF
No ratings yet
Parser and CFG
12 pages
NLP Pos Ner
PDF
No ratings yet
NLP Pos Ner
11 pages