SlideShare a Scribd company logo
1 of 2
Download to read offline
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 stringsRai 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 stringsRai 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 stringsRai 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.pdfamirthagiftsmadurai
 
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
 
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 Functionimtiazalijoono
 
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 cniyamathShariff
 
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.pdfarpaqindia
 
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.comAkanchha 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.docxjaggernaoma
 

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.pdfaaryanentp
 
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.pdfaaryanentp
 
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.pdfaaryanentp
 
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.pdfaaryanentp
 
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.pdfaaryanentp
 
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.pdfaaryanentp
 
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.pdfaaryanentp
 
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.pdfaaryanentp
 
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.pdfaaryanentp
 
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.pdfaaryanentp
 
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.pdfaaryanentp
 
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.pdfaaryanentp
 
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.pdfaaryanentp
 
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 .pdfaaryanentp
 
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 .pdfaaryanentp
 
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.pdfaaryanentp
 
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.pdfaaryanentp
 
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.pdfaaryanentp
 
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.pdfaaryanentp
 
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 .pdfaaryanentp
 

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

Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
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
 
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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Recently uploaded (20)

Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
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...
 
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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 

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]]++; }