SlideShare una empresa de Scribd logo
1 de 25
Abstract ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
General introduction Basic Matrix Multiplication Suppose we want to multiply two matrices of size  N  x  N : for example  A  x  B = C . C 11  = a 11 b 11  + a 12 b 21   C 12  = a 11 b 12  + a 12 b 22   C 21  = a 21 b 11  + a 22 b 21   C 22  = a 21 b 12  + a 22 b 22 2x2 matrix multiplication can be accomplished in  8 multiplication. (2 log 2 8  =2 3 )
Time analysis   Strassens’s Matrix Multiplication   P 1  = (A 11 + A 22 )(B 11 +B 22 )  P 2  = (A 21  + A 22 ) * B 11   P 3  = A 11  * (B 12  - B 22 )  P 4  = A 22  * (B 21  - B 11 )  P 5  = (A 11  + A 12 ) * B 22   P 6  = (A 21  - A 11 ) * (B 11  + B 12 )  P 7  = (A 12  - A 22 ) * (B 21  + B 22 )
C 11  = P 1  + P 4  - P 5  + P 7 C 12  = P 3  + P 5   C 21  = P 2  + P 4   C 22  = P 1  + P 3  - P 2  + P 6   Time analysis
Proposed approach 1: ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ALGORITHM  Matmul(A[n]n],B[n][n],C[n][n]) //The algorithm implements matrix multiplication by dividing matrix in to sub matrix A0,A1,A2,A3…. B0,B1,B2,B3…. And multiplying each of them recursively. //Input: Two matrixes A and B of dimension n  //Output: A matrix  C of dimension n  if (n==2) Multiply the two input matrix by using  Strassens’s Matrix else Divide the matrix in the  sub matrix of dimension n/2  and solve recursively. ,[object Object],[object Object],[object Object]
* Consider Multiplication of 4x4 matrix: A11 A12 A13 A14 A21 A22 A23 A24 A31 A32 A33 A34 A41 A42 A43 A44 B11 B12 B13 B14 B21 B22 B23 B24 B31 B32 B33 B34 B41 B42 B43 B44 C11 C12 C13 C14 C21 C22 C23 C24 C31 C32 C33 C34 C41 C42 C43 C44
 = The sub matrix of size 2x2 can be computed as follows: Now c11 ,c12, c21,c22 can be computed as follows: C 11  = P 1  + P 4  - P 5  + P 7 C 12  = P 3  + P 5   C 21  = P 2  + P 4   C 22  = P 1  + P 3  - P 2  + P 6   P 1  = (A 11 + A 22 )(B 11 +B 22 )  P 2  = (A 21  + A 22 ) * B 11   P 3  = A 11  * (B 12  - B 22 )  P 4  = A 22  * (B 21  - B 11 )  P 5  = (A 11  + A 12 ) * B 22   P 6  = (A 21  - A 11 ) * (B 11  + B 12 )  P 7  = (A 12  - A 22 ) * (B 21  + B 22 )  A11 A12 A21 A22 B11 B12 B21 B22 C11 C12 C21 C22
In similar way we can calculate all the multiplications. And same steps we can perform on any dimension of matrix. Results : Input  Size(n) No.  of multiplication In sequential algo. No. of multiplication In the implemented algo. No. of multiplication In  Strassen’s 2 8 7 7 4 64 56 49 8 512 448 343 16 4096 3584 2401 . . . . . . . . p p 3 (7/8)*p 3 n 2.807
Applying above algorithm when size is not in the power of 2 Steps required is as follows Step 1) Make the size to nearest power of  2 Step 2) Make the value of all extra rows to be zero Step 3) Make the value of all extra columns to be zero Step 4) Then apply above algorithm Suppose the dimension of given matrix is 3 then Nearest of 3 is 4 which is power of  2  Hence matrix becomes A11 A12 A13 0 A21 A22 A23 0 A31 A32 A33 0 0 0 0 0
Efficiency calculation: Time analysis : If the value of dimension is not in the power of 2 then first make it  to the nearest power of 2 then start proceeding…… T(2)=7  ( from base condition of strassen’s multiplication) T(N)= (7/8)*N 3 Hence total no. of multiplication required is =  (7 * n 3 )/8 Which is less then (n 3 ).
Proposed Approach 2: Matrix multiplication by creating process for each computation is as follows: A matrix can be divided in to number of parts and each part can be multiply by creating a separate process.  A new process can be created by using fork  ()  system call. Different steps involved in this approach are Step 1 : Partitioning a) Divide matrices into rows b) Each primitive task has corresponding rows of three matrices  Step 2 : Communication a) Each task must eventually see every row of B b) Organize tasks into a ring Step 3: Agglomeration and mapping a) Fixed number of tasks, each requiring same amount of computation b) Regular communication among tasks c) Strategy: Assign each process a contiguous group of rows
Examples: Let in the first case total no. of process to be created is equal to total no. of rows in the matrix i.e. total no. of process = n where n is the dimension of matrix. Task1 Task2 Task3 Task4 A11 A12 A13 A14 A21 A22 A23 A24 A31 A32 A33 A34 A41 A42 A43 A44
Let in the second case total no. of process to be created is n/2. Task1 Task2 Task3 Task4
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Parent process Child process 1 Child process 2 Child process 3 Child process 4  Child process p Fork  Fork  Fork  Fork  Fork
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Parent process BEGIN … FORALL  i:=1 TO p DO pid=fork()… if(pid==0) call child process END. Child process1 Child process 2 Child process p ...
Prototype for process creation: Prototype for process control: #include <sys/types.h> #include <unistd.h> pid_t fork(void); Returns: 0 in child, process ID of child in parent, -1 on error.  #include <sys/wait.h> pid_t wait(int * status_p );  pid_t waitpid(pid_t  child _ pid , int * status _ p , int  options );  Returns: process ID if OK, 0 (for some variations of wait), -1 on error .
Efficiency: In the first case since we are creating a new process to multiply a row of 1 st  matrix to all columns of 2 nd  matrix. And same operation is performing for all row of 1 st  matrix. Hence we are achieving concurrent programming. Hence efficiency increases much more. In the second case we are creating a new process to multiply two rows of 1 st  matrix to all columns of 2 nd  matrix one by one. And same operation is performing for all sets of 2 rows. Hence here also we are achieving concurrent programming. Hence efficiency increases rapidly.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
BIBLIOGRAPHY  1)Unix system programming using c++ - Terrence Chan 2) Introduction to the design & analysis of algorithms –  Anany Levitin 3) The C Programming Language  - Brian W.Kernighan && Dennnis M.Ritchie, 2 nd  edition
THANK YOU Presented By –PRAMIT KUMAR

Más contenido relacionado

La actualidad más candente

Complex Variable & Numerical Method
Complex Variable & Numerical MethodComplex Variable & Numerical Method
Complex Variable & Numerical MethodNeel Patel
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithmSrikrishnan Suresh
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programmingKrish_ver2
 
Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applicationsyazad dumasia
 
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...Simplilearn
 
Huffman Coding Algorithm Presentation
Huffman Coding Algorithm PresentationHuffman Coding Algorithm Presentation
Huffman Coding Algorithm PresentationAkm Monir
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problemJayesh Chauhan
 
Matrix and its applications by mohammad imran
Matrix and its applications by mohammad imranMatrix and its applications by mohammad imran
Matrix and its applications by mohammad imranMohammad Imran
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cppAlamgir Hossain
 

La actualidad más candente (20)

Complex Variable & Numerical Method
Complex Variable & Numerical MethodComplex Variable & Numerical Method
Complex Variable & Numerical Method
 
Bisection method
Bisection methodBisection method
Bisection method
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
 
Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applications
 
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
 
Presentation-Merge Sort
Presentation-Merge SortPresentation-Merge Sort
Presentation-Merge Sort
 
Huffman Coding Algorithm Presentation
Huffman Coding Algorithm PresentationHuffman Coding Algorithm Presentation
Huffman Coding Algorithm Presentation
 
Polish
PolishPolish
Polish
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problem
 
METHOD OF JACOBI
METHOD OF JACOBIMETHOD OF JACOBI
METHOD OF JACOBI
 
Tsp branch and-bound
Tsp branch and-boundTsp branch and-bound
Tsp branch and-bound
 
Time complexity
Time complexityTime complexity
Time complexity
 
Matrix and its applications by mohammad imran
Matrix and its applications by mohammad imranMatrix and its applications by mohammad imran
Matrix and its applications by mohammad imran
 
Merge sort algorithm power point presentation
Merge sort algorithm power point presentationMerge sort algorithm power point presentation
Merge sort algorithm power point presentation
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
 
Report 02(Binary Search)
Report 02(Binary Search)Report 02(Binary Search)
Report 02(Binary Search)
 
Parsing
ParsingParsing
Parsing
 

Similar a Matrix Multiplication(An example of concurrent programming)

dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)Mumtaz Ali
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptxKokilaK25
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentationManchireddy Reddy
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting classgiridaroori
 
Ayush Jajoo(MCA2501622) AOA .pptx
Ayush Jajoo(MCA2501622) AOA .pptxAyush Jajoo(MCA2501622) AOA .pptx
Ayush Jajoo(MCA2501622) AOA .pptxAmanChoudhary329978
 
CS345-Algorithms-II-Lecture-1-CS345-2016.pdf
CS345-Algorithms-II-Lecture-1-CS345-2016.pdfCS345-Algorithms-II-Lecture-1-CS345-2016.pdf
CS345-Algorithms-II-Lecture-1-CS345-2016.pdfOpenWorld6
 
Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxPJS KUMAR
 
Dynamic programming1
Dynamic programming1Dynamic programming1
Dynamic programming1debolina13
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaPriyanka Rana
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematicalbabuk110
 
Gauss Elimination (without pivot).pptx
Gauss Elimination (without pivot).pptxGauss Elimination (without pivot).pptx
Gauss Elimination (without pivot).pptxSaloni Singhal
 
Parallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel applicationParallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel applicationGeoffrey Fox
 
IRJET- Solving Quadratic Equations using C++ Application Program
IRJET-  	  Solving Quadratic Equations using C++ Application ProgramIRJET-  	  Solving Quadratic Equations using C++ Application Program
IRJET- Solving Quadratic Equations using C++ Application ProgramIRJET Journal
 

Similar a Matrix Multiplication(An example of concurrent programming) (20)

dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting class
 
Daa chapter 3
Daa chapter 3Daa chapter 3
Daa chapter 3
 
Ayush Jajoo(MCA2501622) AOA .pptx
Ayush Jajoo(MCA2501622) AOA .pptxAyush Jajoo(MCA2501622) AOA .pptx
Ayush Jajoo(MCA2501622) AOA .pptx
 
CS345-Algorithms-II-Lecture-1-CS345-2016.pdf
CS345-Algorithms-II-Lecture-1-CS345-2016.pdfCS345-Algorithms-II-Lecture-1-CS345-2016.pdf
CS345-Algorithms-II-Lecture-1-CS345-2016.pdf
 
Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptx
 
Lecture 7.pptx
Lecture 7.pptxLecture 7.pptx
Lecture 7.pptx
 
Dynamic programming1
Dynamic programming1Dynamic programming1
Dynamic programming1
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
 
Gauss Elimination (without pivot).pptx
Gauss Elimination (without pivot).pptxGauss Elimination (without pivot).pptx
Gauss Elimination (without pivot).pptx
 
algo_vc_lecture8.ppt
algo_vc_lecture8.pptalgo_vc_lecture8.ppt
algo_vc_lecture8.ppt
 
Parallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel applicationParallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel application
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
 
IRJET- Solving Quadratic Equations using C++ Application Program
IRJET-  	  Solving Quadratic Equations using C++ Application ProgramIRJET-  	  Solving Quadratic Equations using C++ Application Program
IRJET- Solving Quadratic Equations using C++ Application Program
 

Último

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Último (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

Matrix Multiplication(An example of concurrent programming)

  • 1.
  • 2.
  • 3. General introduction Basic Matrix Multiplication Suppose we want to multiply two matrices of size N x N : for example A x B = C . C 11 = a 11 b 11 + a 12 b 21 C 12 = a 11 b 12 + a 12 b 22 C 21 = a 21 b 11 + a 22 b 21 C 22 = a 21 b 12 + a 22 b 22 2x2 matrix multiplication can be accomplished in 8 multiplication. (2 log 2 8 =2 3 )
  • 4. Time analysis Strassens’s Matrix Multiplication P 1 = (A 11 + A 22 )(B 11 +B 22 ) P 2 = (A 21 + A 22 ) * B 11 P 3 = A 11 * (B 12 - B 22 ) P 4 = A 22 * (B 21 - B 11 ) P 5 = (A 11 + A 12 ) * B 22 P 6 = (A 21 - A 11 ) * (B 11 + B 12 ) P 7 = (A 12 - A 22 ) * (B 21 + B 22 )
  • 5. C 11 = P 1 + P 4 - P 5 + P 7 C 12 = P 3 + P 5 C 21 = P 2 + P 4 C 22 = P 1 + P 3 - P 2 + P 6 Time analysis
  • 6.
  • 7.
  • 8. * Consider Multiplication of 4x4 matrix: A11 A12 A13 A14 A21 A22 A23 A24 A31 A32 A33 A34 A41 A42 A43 A44 B11 B12 B13 B14 B21 B22 B23 B24 B31 B32 B33 B34 B41 B42 B43 B44 C11 C12 C13 C14 C21 C22 C23 C24 C31 C32 C33 C34 C41 C42 C43 C44
  • 9.  = The sub matrix of size 2x2 can be computed as follows: Now c11 ,c12, c21,c22 can be computed as follows: C 11 = P 1 + P 4 - P 5 + P 7 C 12 = P 3 + P 5 C 21 = P 2 + P 4 C 22 = P 1 + P 3 - P 2 + P 6 P 1 = (A 11 + A 22 )(B 11 +B 22 ) P 2 = (A 21 + A 22 ) * B 11 P 3 = A 11 * (B 12 - B 22 ) P 4 = A 22 * (B 21 - B 11 ) P 5 = (A 11 + A 12 ) * B 22 P 6 = (A 21 - A 11 ) * (B 11 + B 12 ) P 7 = (A 12 - A 22 ) * (B 21 + B 22 ) A11 A12 A21 A22 B11 B12 B21 B22 C11 C12 C21 C22
  • 10. In similar way we can calculate all the multiplications. And same steps we can perform on any dimension of matrix. Results : Input Size(n) No. of multiplication In sequential algo. No. of multiplication In the implemented algo. No. of multiplication In Strassen’s 2 8 7 7 4 64 56 49 8 512 448 343 16 4096 3584 2401 . . . . . . . . p p 3 (7/8)*p 3 n 2.807
  • 11. Applying above algorithm when size is not in the power of 2 Steps required is as follows Step 1) Make the size to nearest power of 2 Step 2) Make the value of all extra rows to be zero Step 3) Make the value of all extra columns to be zero Step 4) Then apply above algorithm Suppose the dimension of given matrix is 3 then Nearest of 3 is 4 which is power of 2 Hence matrix becomes A11 A12 A13 0 A21 A22 A23 0 A31 A32 A33 0 0 0 0 0
  • 12. Efficiency calculation: Time analysis : If the value of dimension is not in the power of 2 then first make it to the nearest power of 2 then start proceeding…… T(2)=7 ( from base condition of strassen’s multiplication) T(N)= (7/8)*N 3 Hence total no. of multiplication required is = (7 * n 3 )/8 Which is less then (n 3 ).
  • 13. Proposed Approach 2: Matrix multiplication by creating process for each computation is as follows: A matrix can be divided in to number of parts and each part can be multiply by creating a separate process. A new process can be created by using fork () system call. Different steps involved in this approach are Step 1 : Partitioning a) Divide matrices into rows b) Each primitive task has corresponding rows of three matrices Step 2 : Communication a) Each task must eventually see every row of B b) Organize tasks into a ring Step 3: Agglomeration and mapping a) Fixed number of tasks, each requiring same amount of computation b) Regular communication among tasks c) Strategy: Assign each process a contiguous group of rows
  • 14. Examples: Let in the first case total no. of process to be created is equal to total no. of rows in the matrix i.e. total no. of process = n where n is the dimension of matrix. Task1 Task2 Task3 Task4 A11 A12 A13 A14 A21 A22 A23 A24 A31 A32 A33 A34 A41 A42 A43 A44
  • 15. Let in the second case total no. of process to be created is n/2. Task1 Task2 Task3 Task4
  • 16.
  • 17. Parent process Child process 1 Child process 2 Child process 3 Child process 4 Child process p Fork Fork Fork Fork Fork
  • 18.
  • 19. Prototype for process creation: Prototype for process control: #include <sys/types.h> #include <unistd.h> pid_t fork(void); Returns: 0 in child, process ID of child in parent, -1 on error. #include <sys/wait.h> pid_t wait(int * status_p ); pid_t waitpid(pid_t child _ pid , int * status _ p , int options ); Returns: process ID if OK, 0 (for some variations of wait), -1 on error .
  • 20. Efficiency: In the first case since we are creating a new process to multiply a row of 1 st matrix to all columns of 2 nd matrix. And same operation is performing for all row of 1 st matrix. Hence we are achieving concurrent programming. Hence efficiency increases much more. In the second case we are creating a new process to multiply two rows of 1 st matrix to all columns of 2 nd matrix one by one. And same operation is performing for all sets of 2 rows. Hence here also we are achieving concurrent programming. Hence efficiency increases rapidly.
  • 21.
  • 22.
  • 23.
  • 24. BIBLIOGRAPHY 1)Unix system programming using c++ - Terrence Chan 2) Introduction to the design & analysis of algorithms – Anany Levitin 3) The C Programming Language - Brian W.Kernighan && Dennnis M.Ritchie, 2 nd edition
  • 25. THANK YOU Presented By –PRAMIT KUMAR