SlideShare a Scribd company logo
1 of 2
Download to read offline
Write an MPI program to accomplish the following for a number of processes:
Each processes generate a list of ten random integers (including the process with rand zero) in the
range 0 to 100, sorts them and sends its sorted 10 numbers to the process with rank zero. The
process with rank zero merges all the lists into one list and display them.
The serial program for this question is:
//a.c
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
const int n=10;
int *a, *b, *c;
void Merge(int a[], int b[], int c[]);
void Sort(int* x);
int main()
{
int i;
srand(time(0));
a =(int *)malloc(n*sizeof(int));
b =(int *)malloc(n*sizeof(int));
c =(int *)malloc(2*n*sizeof(int));
for(i = 0; i < n; i++)
{
a[i] = rand()%100;
b[i] = rand()%100;
}
Sort(a);
Sort(b);
Merge(a, b, c);
return 0;
}
int findIndexOfSmallest(int a[], int n, int from){
int indexOfSmallest = from;
int i;
for(i = from; i < n; i++)
if(a[i] < a[indexOfSmallest])
indexOfSmallest = i;
return indexOfSmallest;
}
void Sort(int* x){
// int* x = (int *)a;
int i, indexOfSmallest, t;
for(i = 0; i < n ; i++){
indexOfSmallest = findIndexOfSmallest(x, n, i);
t = x[i];
x[i] = x[indexOfSmallest];
x[indexOfSmallest] = t;
}
for(i = 0; i < n; i++)
printf("%d, ", x[i]);
printf("n------------------------------n");
}
void Merge(int a[], int b[], int c[]){
int aIndex = 0, bIndex = 0, cIndex = 0, i;
while(aIndex < n && bIndex < n)
if(a[aIndex] < b[bIndex])
c[cIndex++] = a[aIndex++];
else
c[cIndex++] = b[bIndex++];
while(aIndex < n)
c[cIndex++] = a[aIndex++];
while(bIndex < n)
c[cIndex++] = b[bIndex++];
for(i = 0; i < 2 * n; i++)
printf("%d, ", c[i]);
printf("n^^^^^^^^^^^^^^^^^^^^^^^^^^n");
}

More Related Content

Similar to Write an MPI program to accomplish the following for a numbe.pdf

54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101premrings
 
C++17 not your father’s c++
C++17  not your father’s c++C++17  not your father’s c++
C++17 not your father’s c++Patrick Viafore
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
 
convert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdfconvert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdfmurtuzadahadwala3
 
C Language Programs
C Language Programs C Language Programs
C Language Programs Mansi Tyagi
 
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfAshutoshprasad27
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxAshutoshprasad27
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysisVishal Singh
 
Core programming in c
Core programming in cCore programming in c
Core programming in cRahul Pandit
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkarsandeep kumbhkar
 
CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL Rishabh-Rawat
 
Xi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsXi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsProf. Dr. K. Adisesha
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical FileAshwin Francis
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2Koshy Geoji
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in cgkgaur1987
 

Similar to Write an MPI program to accomplish the following for a numbe.pdf (20)

54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
C++17 not your father’s c++
C++17  not your father’s c++C++17  not your father’s c++
C++17 not your father’s c++
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
convert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdfconvert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdf
 
C#.net
C#.netC#.net
C#.net
 
C Language Programs
C Language Programs C Language Programs
C Language Programs
 
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
 
week-10x
week-10xweek-10x
week-10x
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL
 
Xi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsXi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programs
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
C lab
C labC lab
C lab
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 

More from agpcorp

Wrte a function gotPC that accepts three arguments UD and .pdf
Wrte a function gotPC that accepts three arguments UD and .pdfWrte a function gotPC that accepts three arguments UD and .pdf
Wrte a function gotPC that accepts three arguments UD and .pdfagpcorp
 
WRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdf
WRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdfWRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdf
WRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdfagpcorp
 
Write TWO recursive methods One to find the maximum in an a.pdf
Write TWO recursive methods One to find the maximum in an a.pdfWrite TWO recursive methods One to find the maximum in an a.pdf
Write TWO recursive methods One to find the maximum in an a.pdfagpcorp
 
Write the R code to generate the following output by using c.pdf
Write the R code to generate the following output by using c.pdfWrite the R code to generate the following output by using c.pdf
Write the R code to generate the following output by using c.pdfagpcorp
 
Write the name of the structure the phrase describes 1 Blo.pdf
Write the name of the structure the phrase describes 1 Blo.pdfWrite the name of the structure the phrase describes 1 Blo.pdf
Write the name of the structure the phrase describes 1 Blo.pdfagpcorp
 
Write TensorFlow program to create a Binary image classifi.pdf
Write TensorFlow program  to  create a Binary image classifi.pdfWrite TensorFlow program  to  create a Binary image classifi.pdf
Write TensorFlow program to create a Binary image classifi.pdfagpcorp
 
Write python code that calculates the minimum maximum mean.pdf
Write python code that calculates the minimum maximum mean.pdfWrite python code that calculates the minimum maximum mean.pdf
Write python code that calculates the minimum maximum mean.pdfagpcorp
 
Write the Asymptotic Complexity for each line of code Then .pdf
Write the Asymptotic Complexity for each line of code Then .pdfWrite the Asymptotic Complexity for each line of code Then .pdf
Write the Asymptotic Complexity for each line of code Then .pdfagpcorp
 
Write Short answers specific and avoid extra off topic det.pdf
Write Short answers specific and avoid extra off topic det.pdfWrite Short answers specific and avoid extra off topic det.pdf
Write Short answers specific and avoid extra off topic det.pdfagpcorp
 
write report that will Evaluate your organizations IT infras.pdf
write report that will Evaluate your organizations IT infras.pdfwrite report that will Evaluate your organizations IT infras.pdf
write report that will Evaluate your organizations IT infras.pdfagpcorp
 
Write the assembly program Can use put_qword_safe to pr.pdf
Write the assembly program Can use put_qword_safe to pr.pdfWrite the assembly program Can use put_qword_safe to pr.pdf
Write the assembly program Can use put_qword_safe to pr.pdfagpcorp
 
Write program in JavaC to sort the given array using merge .pdf
Write program in JavaC to sort the given array using merge .pdfWrite program in JavaC to sort the given array using merge .pdf
Write program in JavaC to sort the given array using merge .pdfagpcorp
 
Write the Asymptotic Complexity for each line of code and th.pdf
Write the Asymptotic Complexity for each line of code and th.pdfWrite the Asymptotic Complexity for each line of code and th.pdf
Write the Asymptotic Complexity for each line of code and th.pdfagpcorp
 
Write the below pseudo code segment using a multipleselecti.pdf
Write the below pseudo code segment using a multipleselecti.pdfWrite the below pseudo code segment using a multipleselecti.pdf
Write the below pseudo code segment using a multipleselecti.pdfagpcorp
 
Write node express application that displays the rectangle f.pdf
Write node express application that displays the rectangle f.pdfWrite node express application that displays the rectangle f.pdf
Write node express application that displays the rectangle f.pdfagpcorp
 
write information about the plant propertieseffects of coca.pdf
write information about the plant propertieseffects of coca.pdfwrite information about the plant propertieseffects of coca.pdf
write information about the plant propertieseffects of coca.pdfagpcorp
 
Write in SML A proper divisor of a natural number is the div.pdf
Write in SML A proper divisor of a natural number is the div.pdfWrite in SML A proper divisor of a natural number is the div.pdf
Write in SML A proper divisor of a natural number is the div.pdfagpcorp
 
Write a main method that will request the user to enter Stri.pdf
Write a main method that will request the user to enter Stri.pdfWrite a main method that will request the user to enter Stri.pdf
Write a main method that will request the user to enter Stri.pdfagpcorp
 
Write combining forms for each of the following terms 1 an.pdf
Write combining forms for each of the following terms 1 an.pdfWrite combining forms for each of the following terms 1 an.pdf
Write combining forms for each of the following terms 1 an.pdfagpcorp
 
Write code for problem 2 please Create a linked list by ent.pdf
Write code for problem 2 please  Create a linked list by ent.pdfWrite code for problem 2 please  Create a linked list by ent.pdf
Write code for problem 2 please Create a linked list by ent.pdfagpcorp
 

More from agpcorp (20)

Wrte a function gotPC that accepts three arguments UD and .pdf
Wrte a function gotPC that accepts three arguments UD and .pdfWrte a function gotPC that accepts three arguments UD and .pdf
Wrte a function gotPC that accepts three arguments UD and .pdf
 
WRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdf
WRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdfWRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdf
WRRK amp MOAILITY AND RALL PREVENTION FOCUS PAIN PAIN 5.pdf
 
Write TWO recursive methods One to find the maximum in an a.pdf
Write TWO recursive methods One to find the maximum in an a.pdfWrite TWO recursive methods One to find the maximum in an a.pdf
Write TWO recursive methods One to find the maximum in an a.pdf
 
Write the R code to generate the following output by using c.pdf
Write the R code to generate the following output by using c.pdfWrite the R code to generate the following output by using c.pdf
Write the R code to generate the following output by using c.pdf
 
Write the name of the structure the phrase describes 1 Blo.pdf
Write the name of the structure the phrase describes 1 Blo.pdfWrite the name of the structure the phrase describes 1 Blo.pdf
Write the name of the structure the phrase describes 1 Blo.pdf
 
Write TensorFlow program to create a Binary image classifi.pdf
Write TensorFlow program  to  create a Binary image classifi.pdfWrite TensorFlow program  to  create a Binary image classifi.pdf
Write TensorFlow program to create a Binary image classifi.pdf
 
Write python code that calculates the minimum maximum mean.pdf
Write python code that calculates the minimum maximum mean.pdfWrite python code that calculates the minimum maximum mean.pdf
Write python code that calculates the minimum maximum mean.pdf
 
Write the Asymptotic Complexity for each line of code Then .pdf
Write the Asymptotic Complexity for each line of code Then .pdfWrite the Asymptotic Complexity for each line of code Then .pdf
Write the Asymptotic Complexity for each line of code Then .pdf
 
Write Short answers specific and avoid extra off topic det.pdf
Write Short answers specific and avoid extra off topic det.pdfWrite Short answers specific and avoid extra off topic det.pdf
Write Short answers specific and avoid extra off topic det.pdf
 
write report that will Evaluate your organizations IT infras.pdf
write report that will Evaluate your organizations IT infras.pdfwrite report that will Evaluate your organizations IT infras.pdf
write report that will Evaluate your organizations IT infras.pdf
 
Write the assembly program Can use put_qword_safe to pr.pdf
Write the assembly program Can use put_qword_safe to pr.pdfWrite the assembly program Can use put_qword_safe to pr.pdf
Write the assembly program Can use put_qword_safe to pr.pdf
 
Write program in JavaC to sort the given array using merge .pdf
Write program in JavaC to sort the given array using merge .pdfWrite program in JavaC to sort the given array using merge .pdf
Write program in JavaC to sort the given array using merge .pdf
 
Write the Asymptotic Complexity for each line of code and th.pdf
Write the Asymptotic Complexity for each line of code and th.pdfWrite the Asymptotic Complexity for each line of code and th.pdf
Write the Asymptotic Complexity for each line of code and th.pdf
 
Write the below pseudo code segment using a multipleselecti.pdf
Write the below pseudo code segment using a multipleselecti.pdfWrite the below pseudo code segment using a multipleselecti.pdf
Write the below pseudo code segment using a multipleselecti.pdf
 
Write node express application that displays the rectangle f.pdf
Write node express application that displays the rectangle f.pdfWrite node express application that displays the rectangle f.pdf
Write node express application that displays the rectangle f.pdf
 
write information about the plant propertieseffects of coca.pdf
write information about the plant propertieseffects of coca.pdfwrite information about the plant propertieseffects of coca.pdf
write information about the plant propertieseffects of coca.pdf
 
Write in SML A proper divisor of a natural number is the div.pdf
Write in SML A proper divisor of a natural number is the div.pdfWrite in SML A proper divisor of a natural number is the div.pdf
Write in SML A proper divisor of a natural number is the div.pdf
 
Write a main method that will request the user to enter Stri.pdf
Write a main method that will request the user to enter Stri.pdfWrite a main method that will request the user to enter Stri.pdf
Write a main method that will request the user to enter Stri.pdf
 
Write combining forms for each of the following terms 1 an.pdf
Write combining forms for each of the following terms 1 an.pdfWrite combining forms for each of the following terms 1 an.pdf
Write combining forms for each of the following terms 1 an.pdf
 
Write code for problem 2 please Create a linked list by ent.pdf
Write code for problem 2 please  Create a linked list by ent.pdfWrite code for problem 2 please  Create a linked list by ent.pdf
Write code for problem 2 please Create a linked list by ent.pdf
 

Recently uploaded

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 

Recently uploaded (20)

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

Write an MPI program to accomplish the following for a numbe.pdf

  • 1. Write an MPI program to accomplish the following for a number of processes: Each processes generate a list of ten random integers (including the process with rand zero) in the range 0 to 100, sorts them and sends its sorted 10 numbers to the process with rank zero. The process with rank zero merges all the lists into one list and display them. The serial program for this question is: //a.c #include <stdio.h> #include <stdio.h> #include <stdlib.h> #include<time.h> const int n=10; int *a, *b, *c; void Merge(int a[], int b[], int c[]); void Sort(int* x); int main() { int i; srand(time(0)); a =(int *)malloc(n*sizeof(int)); b =(int *)malloc(n*sizeof(int)); c =(int *)malloc(2*n*sizeof(int)); for(i = 0; i < n; i++) { a[i] = rand()%100; b[i] = rand()%100; } Sort(a); Sort(b); Merge(a, b, c); return 0; } int findIndexOfSmallest(int a[], int n, int from){ int indexOfSmallest = from; int i; for(i = from; i < n; i++) if(a[i] < a[indexOfSmallest]) indexOfSmallest = i; return indexOfSmallest; } void Sort(int* x){ // int* x = (int *)a; int i, indexOfSmallest, t;
  • 2. for(i = 0; i < n ; i++){ indexOfSmallest = findIndexOfSmallest(x, n, i); t = x[i]; x[i] = x[indexOfSmallest]; x[indexOfSmallest] = t; } for(i = 0; i < n; i++) printf("%d, ", x[i]); printf("n------------------------------n"); } void Merge(int a[], int b[], int c[]){ int aIndex = 0, bIndex = 0, cIndex = 0, i; while(aIndex < n && bIndex < n) if(a[aIndex] < b[bIndex]) c[cIndex++] = a[aIndex++]; else c[cIndex++] = b[bIndex++]; while(aIndex < n) c[cIndex++] = a[aIndex++]; while(bIndex < n) c[cIndex++] = b[bIndex++]; for(i = 0; i < 2 * n; i++) printf("%d, ", c[i]); printf("n^^^^^^^^^^^^^^^^^^^^^^^^^^n"); }