SlideShare a Scribd company logo
Write a parallel program using MPI (and not OpeMP) to accomplish the same as the following
serial program. For the following serial program the user enters a line and the program outputs the
number of occurrences of each printable character (but not the space or tab character).
For the parallel program if we have p processes we should divide the line into p segments and let
each process counts the characters of its segment.
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#define ASCIIs 127 //ASCII characters from 0 to 127
#define atmost 1000
char letters[atmost + 1]; //Extra location for the string terminator '0'
int total_count[ASCIIs];
void find(int count[], int start, int end);
int main()
{
int i, processes, n, start, end;
int count[ASCIIs], my_rank, segment, p;
printf("Enter a line not larger than 1000 characters.n");
fgets(letters, atmost,stdin);
printf("How many segments?: ");
scanf("%d", &processes);
//To make the length of the divisible by processes:
while(strlen(letters) % processes != 0) strcat(letters, " ");
n = strlen(letters);
for(i = 0; i < ASCIIs; i++)
total_count[i] = 0;
for(p = 0; p < processes; p++)
{
my_rank = p;
segment = n / processes;
start = my_rank * segment;
end = start + segment;
find(count, start, end);
for(i = 0; i <= ASCIIs; i++)
total_count[i] += count[i];
}
for(i = 33; i < ASCIIs; i++)
if(total_count[i] != 0)
printf("Number of %c is: %dn", i, total_count[i]);
return 0;
}
void find(int count[], int start, int end)
{
int i;
for(i = 0; i < ASCIIs; i++)
count[i] = 0;
for(i = start; i < end; i++)
count[(int)letters[i]]++;
}

More Related Content

Similar to Write a parallel program using MPI and not OpeMP to accomp.pdf

Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
Rai University
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
Rai University
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
Rai University
 
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdfUsing the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
amirthagiftsmadurai
 
Lecture 05 2017
Lecture 05 2017Lecture 05 2017
Lecture 05 2017
Jesmin Akhter
 
Input-output
Input-outputInput-output
Input-output
neda marie maramo
 
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
 
string , pointer
string , pointerstring , pointer
string , pointer
Arafat Bin Reza
 
Introduction to Input/Output Functions in C
Introduction to Input/Output Functions in CIntroduction to Input/Output Functions in C
Introduction to Input/Output Functions in C
Thesis Scientist Private Limited
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in c
niyamathShariff
 
Functions of stdio conio
Functions of stdio   conio Functions of stdio   conio
Functions of stdio conio
Bhavik Vashi
 
You are required to open an input file (shown below) then read one c.pdf
You are required to open an input file (shown below) then read one c.pdfYou are required to open an input file (shown below) then read one c.pdf
You are required to open an input file (shown below) then read one c.pdf
arpaqindia
 
Tut1
Tut1Tut1
String notes
String notesString notes
String notes
Prasadu Peddi
 
2 data and c
2 data and c2 data and c
2 data and c
MomenMostafa
 
Basic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comBasic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.com
Akanchha Agrawal
 
INPUT AND OUTPUT PROCESSINGPlease note that the material o.docx
INPUT AND OUTPUT PROCESSINGPlease note that the material o.docxINPUT AND OUTPUT PROCESSINGPlease note that the material o.docx
INPUT AND OUTPUT PROCESSINGPlease note that the material o.docx
jaggernaoma
 

Similar to Write a parallel program using MPI and not OpeMP to accomp.pdf (20)

Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
 
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdfUsing the Ceasar Cipher encryption algorithm, you take each characte.pdf
Using the Ceasar Cipher encryption algorithm, you take each characte.pdf
 
Input And Output
 Input And Output Input And Output
Input And Output
 
Lecture 05 2017
Lecture 05 2017Lecture 05 2017
Lecture 05 2017
 
Input-output
Input-outputInput-output
Input-output
 
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
 
string , pointer
string , pointerstring , pointer
string , pointer
 
Introduction to Input/Output Functions in C
Introduction to Input/Output Functions in CIntroduction to Input/Output Functions in C
Introduction to Input/Output Functions in C
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
Basic Input and Output
Basic Input and OutputBasic Input and Output
Basic Input and Output
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in c
 
Functions of stdio conio
Functions of stdio   conio Functions of stdio   conio
Functions of stdio conio
 
You are required to open an input file (shown below) then read one c.pdf
You are required to open an input file (shown below) then read one c.pdfYou are required to open an input file (shown below) then read one c.pdf
You are required to open an input file (shown below) then read one c.pdf
 
Tut1
Tut1Tut1
Tut1
 
String notes
String notesString notes
String notes
 
2 data and c
2 data and c2 data and c
2 data and c
 
Basic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comBasic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.com
 
INPUT AND OUTPUT PROCESSINGPlease note that the material o.docx
INPUT AND OUTPUT PROCESSINGPlease note that the material o.docxINPUT AND OUTPUT PROCESSINGPlease note that the material o.docx
INPUT AND OUTPUT PROCESSINGPlease note that the material o.docx
 

More from aaryanentp

ZZZZ Best durumunda denetilerin toplad kant trlerini ve d.pdf
ZZZZ Best durumunda denetilerin toplad kant trlerini ve d.pdfZZZZ Best durumunda denetilerin toplad kant trlerini ve d.pdf
ZZZZ Best durumunda denetilerin toplad kant trlerini ve d.pdf
aaryanentp
 
Zahra a supervisor at Artworx Inc observes two of her emp.pdf
Zahra a supervisor at Artworx Inc observes two of her emp.pdfZahra a supervisor at Artworx Inc observes two of her emp.pdf
Zahra a supervisor at Artworx Inc observes two of her emp.pdf
aaryanentp
 
Zachary Fox does not make any voluntary deductions that impa.pdf
Zachary Fox does not make any voluntary deductions that impa.pdfZachary Fox does not make any voluntary deductions that impa.pdf
Zachary Fox does not make any voluntary deductions that impa.pdf
aaryanentp
 
Youve surely seen a sevensegment display Its a device s.pdf
Youve surely seen a sevensegment display Its a device s.pdfYouve surely seen a sevensegment display Its a device s.pdf
Youve surely seen a sevensegment display Its a device s.pdf
aaryanentp
 
Your selected organizations strategy is to be included Beg.pdf
Your selected organizations strategy is to be included Beg.pdfYour selected organizations strategy is to be included Beg.pdf
Your selected organizations strategy is to be included Beg.pdf
aaryanentp
 
Your company wishes to expand internationally and needs to f.pdf
Your company wishes to expand internationally and needs to f.pdfYour company wishes to expand internationally and needs to f.pdf
Your company wishes to expand internationally and needs to f.pdf
aaryanentp
 
You will choose a company familiar to you or that youre int.pdf
You will choose a company familiar to you or that youre int.pdfYou will choose a company familiar to you or that youre int.pdf
You will choose a company familiar to you or that youre int.pdf
aaryanentp
 
You want to save 2000 today for retirement in 40 years You.pdf
You want to save 2000 today for retirement in 40 years You.pdfYou want to save 2000 today for retirement in 40 years You.pdf
You want to save 2000 today for retirement in 40 years You.pdf
aaryanentp
 
You have recently joined the accounting firm Comtois Benoit.pdf
You have recently joined the accounting firm Comtois Benoit.pdfYou have recently joined the accounting firm Comtois Benoit.pdf
You have recently joined the accounting firm Comtois Benoit.pdf
aaryanentp
 
You have three alternatives to invest A1 Stocks A2 Bond.pdf
You have three alternatives to invest A1 Stocks A2  Bond.pdfYou have three alternatives to invest A1 Stocks A2  Bond.pdf
You have three alternatives to invest A1 Stocks A2 Bond.pdf
aaryanentp
 
You have helped authors develop a number of figures and tabl.pdf
You have helped authors develop a number of figures and tabl.pdfYou have helped authors develop a number of figures and tabl.pdf
You have helped authors develop a number of figures and tabl.pdf
aaryanentp
 
You know that most people use someones birthday as the 4di.pdf
You know that most people use someones birthday as the 4di.pdfYou know that most people use someones birthday as the 4di.pdf
You know that most people use someones birthday as the 4di.pdf
aaryanentp
 
You have come onto the unit after report You are required t.pdf
You have come onto the unit after report You are required t.pdfYou have come onto the unit after report You are required t.pdf
You have come onto the unit after report You are required t.pdf
aaryanentp
 
you have a portfolio consisting solely of Stock A and Stock .pdf
you have a portfolio consisting solely of Stock A and Stock .pdfyou have a portfolio consisting solely of Stock A and Stock .pdf
you have a portfolio consisting solely of Stock A and Stock .pdf
aaryanentp
 
You are designing an application that allows users to input .pdf
You are designing an application that allows users to input .pdfYou are designing an application that allows users to input .pdf
You are designing an application that allows users to input .pdf
aaryanentp
 
You are required to present a research report in which you h.pdf
You are required to present a research report in which you h.pdfYou are required to present a research report in which you h.pdf
You are required to present a research report in which you h.pdf
aaryanentp
 
You are at a professional association reception and you are.pdf
You are at a professional association reception and you are.pdfYou are at a professional association reception and you are.pdf
You are at a professional association reception and you are.pdf
aaryanentp
 
You are a senior manager in an industry of your choosing Se.pdf
You are a senior manager in an industry of your choosing Se.pdfYou are a senior manager in an industry of your choosing Se.pdf
You are a senior manager in an industry of your choosing Se.pdf
aaryanentp
 
yi bir etki lm stratejisi SElerin alar etrafndaki potan.pdf
yi bir etki lm stratejisi SElerin alar etrafndaki potan.pdfyi bir etki lm stratejisi SElerin alar etrafndaki potan.pdf
yi bir etki lm stratejisi SElerin alar etrafndaki potan.pdf
aaryanentp
 
write the precis of the following passage and give suitable .pdf
write the precis of the following passage and give suitable .pdfwrite the precis of the following passage and give suitable .pdf
write the precis of the following passage and give suitable .pdf
aaryanentp
 

More from aaryanentp (20)

ZZZZ Best durumunda denetilerin toplad kant trlerini ve d.pdf
ZZZZ Best durumunda denetilerin toplad kant trlerini ve d.pdfZZZZ Best durumunda denetilerin toplad kant trlerini ve d.pdf
ZZZZ Best durumunda denetilerin toplad kant trlerini ve d.pdf
 
Zahra a supervisor at Artworx Inc observes two of her emp.pdf
Zahra a supervisor at Artworx Inc observes two of her emp.pdfZahra a supervisor at Artworx Inc observes two of her emp.pdf
Zahra a supervisor at Artworx Inc observes two of her emp.pdf
 
Zachary Fox does not make any voluntary deductions that impa.pdf
Zachary Fox does not make any voluntary deductions that impa.pdfZachary Fox does not make any voluntary deductions that impa.pdf
Zachary Fox does not make any voluntary deductions that impa.pdf
 
Youve surely seen a sevensegment display Its a device s.pdf
Youve surely seen a sevensegment display Its a device s.pdfYouve surely seen a sevensegment display Its a device s.pdf
Youve surely seen a sevensegment display Its a device s.pdf
 
Your selected organizations strategy is to be included Beg.pdf
Your selected organizations strategy is to be included Beg.pdfYour selected organizations strategy is to be included Beg.pdf
Your selected organizations strategy is to be included Beg.pdf
 
Your company wishes to expand internationally and needs to f.pdf
Your company wishes to expand internationally and needs to f.pdfYour company wishes to expand internationally and needs to f.pdf
Your company wishes to expand internationally and needs to f.pdf
 
You will choose a company familiar to you or that youre int.pdf
You will choose a company familiar to you or that youre int.pdfYou will choose a company familiar to you or that youre int.pdf
You will choose a company familiar to you or that youre int.pdf
 
You want to save 2000 today for retirement in 40 years You.pdf
You want to save 2000 today for retirement in 40 years You.pdfYou want to save 2000 today for retirement in 40 years You.pdf
You want to save 2000 today for retirement in 40 years You.pdf
 
You have recently joined the accounting firm Comtois Benoit.pdf
You have recently joined the accounting firm Comtois Benoit.pdfYou have recently joined the accounting firm Comtois Benoit.pdf
You have recently joined the accounting firm Comtois Benoit.pdf
 
You have three alternatives to invest A1 Stocks A2 Bond.pdf
You have three alternatives to invest A1 Stocks A2  Bond.pdfYou have three alternatives to invest A1 Stocks A2  Bond.pdf
You have three alternatives to invest A1 Stocks A2 Bond.pdf
 
You have helped authors develop a number of figures and tabl.pdf
You have helped authors develop a number of figures and tabl.pdfYou have helped authors develop a number of figures and tabl.pdf
You have helped authors develop a number of figures and tabl.pdf
 
You know that most people use someones birthday as the 4di.pdf
You know that most people use someones birthday as the 4di.pdfYou know that most people use someones birthday as the 4di.pdf
You know that most people use someones birthday as the 4di.pdf
 
You have come onto the unit after report You are required t.pdf
You have come onto the unit after report You are required t.pdfYou have come onto the unit after report You are required t.pdf
You have come onto the unit after report You are required t.pdf
 
you have a portfolio consisting solely of Stock A and Stock .pdf
you have a portfolio consisting solely of Stock A and Stock .pdfyou have a portfolio consisting solely of Stock A and Stock .pdf
you have a portfolio consisting solely of Stock A and Stock .pdf
 
You are designing an application that allows users to input .pdf
You are designing an application that allows users to input .pdfYou are designing an application that allows users to input .pdf
You are designing an application that allows users to input .pdf
 
You are required to present a research report in which you h.pdf
You are required to present a research report in which you h.pdfYou are required to present a research report in which you h.pdf
You are required to present a research report in which you h.pdf
 
You are at a professional association reception and you are.pdf
You are at a professional association reception and you are.pdfYou are at a professional association reception and you are.pdf
You are at a professional association reception and you are.pdf
 
You are a senior manager in an industry of your choosing Se.pdf
You are a senior manager in an industry of your choosing Se.pdfYou are a senior manager in an industry of your choosing Se.pdf
You are a senior manager in an industry of your choosing Se.pdf
 
yi bir etki lm stratejisi SElerin alar etrafndaki potan.pdf
yi bir etki lm stratejisi SElerin alar etrafndaki potan.pdfyi bir etki lm stratejisi SElerin alar etrafndaki potan.pdf
yi bir etki lm stratejisi SElerin alar etrafndaki potan.pdf
 
write the precis of the following passage and give suitable .pdf
write the precis of the following passage and give suitable .pdfwrite the precis of the following passage and give suitable .pdf
write the precis of the following passage and give suitable .pdf
 

Recently uploaded

Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
christianmathematics
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Ashish Kohli
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 

Recently uploaded (20)

Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 

Write a parallel program using MPI and not OpeMP to accomp.pdf

  • 1. Write a parallel program using MPI (and not OpeMP) to accomplish the same as the following serial program. For the following serial program the user enters a line and the program outputs the number of occurrences of each printable character (but not the space or tab character). For the parallel program if we have p processes we should divide the line into p segments and let each process counts the characters of its segment. #include<stdio.h> #include<stdlib.h> #include <string.h> #define ASCIIs 127 //ASCII characters from 0 to 127 #define atmost 1000 char letters[atmost + 1]; //Extra location for the string terminator '0' int total_count[ASCIIs]; void find(int count[], int start, int end); int main() { int i, processes, n, start, end; int count[ASCIIs], my_rank, segment, p; printf("Enter a line not larger than 1000 characters.n"); fgets(letters, atmost,stdin); printf("How many segments?: "); scanf("%d", &processes); //To make the length of the divisible by processes: while(strlen(letters) % processes != 0) strcat(letters, " "); n = strlen(letters); for(i = 0; i < ASCIIs; i++) total_count[i] = 0; for(p = 0; p < processes; p++) { my_rank = p; segment = n / processes; start = my_rank * segment; end = start + segment; find(count, start, end); for(i = 0; i <= ASCIIs; i++) total_count[i] += count[i]; } for(i = 33; i < ASCIIs; i++) if(total_count[i] != 0) printf("Number of %c is: %dn", i, total_count[i]); return 0; } void find(int count[], int start, int end)
  • 2. { int i; for(i = 0; i < ASCIIs; i++) count[i] = 0; for(i = start; i < end; i++) count[(int)letters[i]]++; }