SlideShare a Scribd company logo
Using an Array:
#include <stdio.h>
#include <mpi.h>
int main(int argc, char** argv) {
int rank, size;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
// Define topology
int topology[5][2] = {{1, 4}, {0, 2, 3}, {1,-1}, {0, 4}, {0, 3}};
// Initialize index and edge arrays
int index[5] = {0};
int edges[5][3] = {{0}};
// Add edges into index array
int i =0;
int j =0;
for (i = 0; i < 5; i++)
{
index[i] = sizeof(topology[i]) / sizeof(int);
for (j = 0; j < index[i]; j++)
{
edges[i][j] = topology[i][j];
}
}
// Display topology for each process
for (i = 0; i < size; i++)
{
if (rank == i)
{
printf("Process %d has %d neighbors: ", i, index[i]);
for (j = 0; j < index[i]; j++)
{
printf("%d ", edges[i][j]);
}
printf("n");
}
MPI_Barrier(MPI_COMM_WORLD);
}
MPI_Finalize();
return 0;
}
MPI Functions:
#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv)
{
int rank, size;
MPI_Init(&argc, &argv); // Initialize MPI
MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Get the rank of the current process
MPI_Comm_size(MPI_COMM_WORLD, &size); // Get the total number of processes
int nnodes = 5; // Number of nodes in the topology
int nedges = 8; // Number of edges in the topolofy
// Index of the first edge for each node
int index[5] = {2, 5, 6, 8, 9};
int edges[9] = {4, 1, 0, 2, 3, 1, 4, 0, 3}; // List of all edges
MPI_Comm graph_comm; // Create a new communicator for the graph topology
MPI_Graph_create(MPI_COMM_WORLD, nnodes, index, edges, 0, &graph_comm); // Create the
graph topology
int count; // Number of neighbors
int* neighbors; // Neighbor Ranks
MPI_Graph_neighbors_count(graph_comm, rank, &count); // Get the number of neighbors for the
current process
neighbors = (int*) malloc(count * sizeof(int)); // Allocate memory for the array of neighbor ranks
MPI_Graph_neighbors(graph_comm, rank, count, neighbors); // Get the neighbor ranks for the
current process
// Display process and the node in the topologies neighbors
printf("Process %d has %d neighbors:", rank, count);
int i;
for (i = 0; i < count; i++)
{
printf(" %d", neighbors[i]); // Print the neighbor ranks
}
printf("n");
MPI_Finalize();
return 0;
}
ive provided my own code above in case that helps or makes it easier on you guys.
My output isnt quite right ive been at it for a while if someone could fix the output and explain it to
me id be very happy :)
4. Use Graph topology to create following one. Once you create your topology, use one process
(e.g., process 0 ) to display the number of neighbors and its neighbors at each node (i.e.,
process). Use following two methods to check your topology. (20 points) i) Use two arrays, index
and edges, to display number of neighbors and its neighbors for each node. ii) Use two functions
in MPI, "MPI Graph neighbors count" and "MPI Graph neighbors". llinn@scholar-fe06: /470 $
mpirun -n 5 ./hmwk5q4-b Process 0 has 2 neighbors: 41 Process 1 has 3 neighbors: 023 Process
2 has 1 neighbors: 1 Process 3 has 2 neighbors: 40

More Related Content

Similar to Using an Array include ltstdiohgt include ltmpih.pdf

Unit 3
Unit 3 Unit 3
Unit 3
GOWSIKRAJAP
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab File
Kandarp Tiwari
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
Icaii Infotech
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstack
Thierry Gayet
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
Andreas Dewes
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in cgkgaur1987
 
#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf
anandmobile
 
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfQ1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
abdulrahamanbags
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
Prof. Dr. K. Adisesha
 
Write a C code to perform the following tasks In main Define an arr.pdf
Write a C code to perform the following tasks In main Define an arr.pdfWrite a C code to perform the following tasks In main Define an arr.pdf
Write a C code to perform the following tasks In main Define an arr.pdf
fabmallkochi
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
Guy Komari
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdf
janakim15
 
C
CC
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
amrit47
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
fashiongallery1
 

Similar to Using an Array include ltstdiohgt include ltmpih.pdf (20)

C
CC
C
 
C
CC
C
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab File
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstack
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf
 
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfQ1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
Write a C code to perform the following tasks In main Define an arr.pdf
Write a C code to perform the following tasks In main Define an arr.pdfWrite a C code to perform the following tasks In main Define an arr.pdf
Write a C code to perform the following tasks In main Define an arr.pdf
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdf
 
C
CC
C
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 

More from giriraj65

Which of these refers to the degree and nature of interdepen.pdf
Which of these refers to the degree and nature of interdepen.pdfWhich of these refers to the degree and nature of interdepen.pdf
Which of these refers to the degree and nature of interdepen.pdf
giriraj65
 
Wheat crops across the Americas Asia Europe and Africa ar.pdf
Wheat crops across the Americas Asia Europe and Africa ar.pdfWheat crops across the Americas Asia Europe and Africa ar.pdf
Wheat crops across the Americas Asia Europe and Africa ar.pdf
giriraj65
 
The resto txt Use for TM254 2021J TMA02 Question 6 .pdf
The resto txt     Use for TM254 2021J TMA02 Question 6 .pdfThe resto txt     Use for TM254 2021J TMA02 Question 6 .pdf
The resto txt Use for TM254 2021J TMA02 Question 6 .pdf
giriraj65
 
Tableau DA 33 MiniCase Analyzing adjusting entries and p.pdf
Tableau DA 33 MiniCase Analyzing adjusting entries and p.pdfTableau DA 33 MiniCase Analyzing adjusting entries and p.pdf
Tableau DA 33 MiniCase Analyzing adjusting entries and p.pdf
giriraj65
 
Rios Co is a regional insurance company that began operatio.pdf
Rios Co is a regional insurance company that began operatio.pdfRios Co is a regional insurance company that began operatio.pdf
Rios Co is a regional insurance company that began operatio.pdf
giriraj65
 
Question 1 2 pts Which of the following can be absolute defe.pdf
Question 1 2 pts Which of the following can be absolute defe.pdfQuestion 1 2 pts Which of the following can be absolute defe.pdf
Question 1 2 pts Which of the following can be absolute defe.pdf
giriraj65
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
giriraj65
 
Problem 6 Create the Kmaps and then simplify for the followi.pdf
Problem 6 Create the Kmaps and then simplify for the followi.pdfProblem 6 Create the Kmaps and then simplify for the followi.pdf
Problem 6 Create the Kmaps and then simplify for the followi.pdf
giriraj65
 
PLEASE ANSWER PART A B C D Thank you Kingbird Inc uses.pdf
PLEASE ANSWER PART A B C D  Thank you Kingbird Inc uses.pdfPLEASE ANSWER PART A B C D  Thank you Kingbird Inc uses.pdf
PLEASE ANSWER PART A B C D Thank you Kingbird Inc uses.pdf
giriraj65
 
Please discuss the following i Using examples for each typ.pdf
Please discuss the following i Using examples for each typ.pdfPlease discuss the following i Using examples for each typ.pdf
Please discuss the following i Using examples for each typ.pdf
giriraj65
 
Mill Company began operations on January 1201 and recogni.pdf
Mill Company began operations on January 1201 and recogni.pdfMill Company began operations on January 1201 and recogni.pdf
Mill Company began operations on January 1201 and recogni.pdf
giriraj65
 
For each situation described below indicate which financial.pdf
For each situation described below indicate which financial.pdfFor each situation described below indicate which financial.pdf
For each situation described below indicate which financial.pdf
giriraj65
 
Exercise I Georgettes and Georges Genotypes Gene 1 Geor.pdf
Exercise I Georgettes and Georges Genotypes Gene 1  Geor.pdfExercise I Georgettes and Georges Genotypes Gene 1  Geor.pdf
Exercise I Georgettes and Georges Genotypes Gene 1 Geor.pdf
giriraj65
 
El 23 de enero se adquieren 17000 acciones de Tolle Company.pdf
El 23 de enero se adquieren 17000 acciones de Tolle Company.pdfEl 23 de enero se adquieren 17000 acciones de Tolle Company.pdf
El 23 de enero se adquieren 17000 acciones de Tolle Company.pdf
giriraj65
 
Ests realizando experimentos de mejoramiento en maz Comie.pdf
Ests realizando experimentos de mejoramiento en maz Comie.pdfEsts realizando experimentos de mejoramiento en maz Comie.pdf
Ests realizando experimentos de mejoramiento en maz Comie.pdf
giriraj65
 
Assume that a cross is made between AaBb and aabb plants and.pdf
Assume that a cross is made between AaBb and aabb plants and.pdfAssume that a cross is made between AaBb and aabb plants and.pdf
Assume that a cross is made between AaBb and aabb plants and.pdf
giriraj65
 
a How much money was eriginally invested t Show that th.pdf
a How much money was eriginally invested t Show that th.pdfa How much money was eriginally invested t Show that th.pdf
a How much money was eriginally invested t Show that th.pdf
giriraj65
 
A Bucle remolino y arco B Crestas surcos y colinas .pdf
A  Bucle remolino y arco   B  Crestas surcos y colinas  .pdfA  Bucle remolino y arco   B  Crestas surcos y colinas  .pdf
A Bucle remolino y arco B Crestas surcos y colinas .pdf
giriraj65
 
68 Exercise Ferris Corporation makes a single product a f.pdf
68 Exercise Ferris Corporation makes a single product  a f.pdf68 Exercise Ferris Corporation makes a single product  a f.pdf
68 Exercise Ferris Corporation makes a single product a f.pdf
giriraj65
 
A special interest speaks for a position or program which 1.pdf
A special interest speaks for a position or program which 1.pdfA special interest speaks for a position or program which 1.pdf
A special interest speaks for a position or program which 1.pdf
giriraj65
 

More from giriraj65 (20)

Which of these refers to the degree and nature of interdepen.pdf
Which of these refers to the degree and nature of interdepen.pdfWhich of these refers to the degree and nature of interdepen.pdf
Which of these refers to the degree and nature of interdepen.pdf
 
Wheat crops across the Americas Asia Europe and Africa ar.pdf
Wheat crops across the Americas Asia Europe and Africa ar.pdfWheat crops across the Americas Asia Europe and Africa ar.pdf
Wheat crops across the Americas Asia Europe and Africa ar.pdf
 
The resto txt Use for TM254 2021J TMA02 Question 6 .pdf
The resto txt     Use for TM254 2021J TMA02 Question 6 .pdfThe resto txt     Use for TM254 2021J TMA02 Question 6 .pdf
The resto txt Use for TM254 2021J TMA02 Question 6 .pdf
 
Tableau DA 33 MiniCase Analyzing adjusting entries and p.pdf
Tableau DA 33 MiniCase Analyzing adjusting entries and p.pdfTableau DA 33 MiniCase Analyzing adjusting entries and p.pdf
Tableau DA 33 MiniCase Analyzing adjusting entries and p.pdf
 
Rios Co is a regional insurance company that began operatio.pdf
Rios Co is a regional insurance company that began operatio.pdfRios Co is a regional insurance company that began operatio.pdf
Rios Co is a regional insurance company that began operatio.pdf
 
Question 1 2 pts Which of the following can be absolute defe.pdf
Question 1 2 pts Which of the following can be absolute defe.pdfQuestion 1 2 pts Which of the following can be absolute defe.pdf
Question 1 2 pts Which of the following can be absolute defe.pdf
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
 
Problem 6 Create the Kmaps and then simplify for the followi.pdf
Problem 6 Create the Kmaps and then simplify for the followi.pdfProblem 6 Create the Kmaps and then simplify for the followi.pdf
Problem 6 Create the Kmaps and then simplify for the followi.pdf
 
PLEASE ANSWER PART A B C D Thank you Kingbird Inc uses.pdf
PLEASE ANSWER PART A B C D  Thank you Kingbird Inc uses.pdfPLEASE ANSWER PART A B C D  Thank you Kingbird Inc uses.pdf
PLEASE ANSWER PART A B C D Thank you Kingbird Inc uses.pdf
 
Please discuss the following i Using examples for each typ.pdf
Please discuss the following i Using examples for each typ.pdfPlease discuss the following i Using examples for each typ.pdf
Please discuss the following i Using examples for each typ.pdf
 
Mill Company began operations on January 1201 and recogni.pdf
Mill Company began operations on January 1201 and recogni.pdfMill Company began operations on January 1201 and recogni.pdf
Mill Company began operations on January 1201 and recogni.pdf
 
For each situation described below indicate which financial.pdf
For each situation described below indicate which financial.pdfFor each situation described below indicate which financial.pdf
For each situation described below indicate which financial.pdf
 
Exercise I Georgettes and Georges Genotypes Gene 1 Geor.pdf
Exercise I Georgettes and Georges Genotypes Gene 1  Geor.pdfExercise I Georgettes and Georges Genotypes Gene 1  Geor.pdf
Exercise I Georgettes and Georges Genotypes Gene 1 Geor.pdf
 
El 23 de enero se adquieren 17000 acciones de Tolle Company.pdf
El 23 de enero se adquieren 17000 acciones de Tolle Company.pdfEl 23 de enero se adquieren 17000 acciones de Tolle Company.pdf
El 23 de enero se adquieren 17000 acciones de Tolle Company.pdf
 
Ests realizando experimentos de mejoramiento en maz Comie.pdf
Ests realizando experimentos de mejoramiento en maz Comie.pdfEsts realizando experimentos de mejoramiento en maz Comie.pdf
Ests realizando experimentos de mejoramiento en maz Comie.pdf
 
Assume that a cross is made between AaBb and aabb plants and.pdf
Assume that a cross is made between AaBb and aabb plants and.pdfAssume that a cross is made between AaBb and aabb plants and.pdf
Assume that a cross is made between AaBb and aabb plants and.pdf
 
a How much money was eriginally invested t Show that th.pdf
a How much money was eriginally invested t Show that th.pdfa How much money was eriginally invested t Show that th.pdf
a How much money was eriginally invested t Show that th.pdf
 
A Bucle remolino y arco B Crestas surcos y colinas .pdf
A  Bucle remolino y arco   B  Crestas surcos y colinas  .pdfA  Bucle remolino y arco   B  Crestas surcos y colinas  .pdf
A Bucle remolino y arco B Crestas surcos y colinas .pdf
 
68 Exercise Ferris Corporation makes a single product a f.pdf
68 Exercise Ferris Corporation makes a single product  a f.pdf68 Exercise Ferris Corporation makes a single product  a f.pdf
68 Exercise Ferris Corporation makes a single product a f.pdf
 
A special interest speaks for a position or program which 1.pdf
A special interest speaks for a position or program which 1.pdfA special interest speaks for a position or program which 1.pdf
A special interest speaks for a position or program which 1.pdf
 

Recently uploaded

"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
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
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 

Recently uploaded (20)

"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
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
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 

Using an Array include ltstdiohgt include ltmpih.pdf

  • 1. Using an Array: #include <stdio.h> #include <mpi.h> int main(int argc, char** argv) { int rank, size; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); // Define topology int topology[5][2] = {{1, 4}, {0, 2, 3}, {1,-1}, {0, 4}, {0, 3}}; // Initialize index and edge arrays int index[5] = {0}; int edges[5][3] = {{0}}; // Add edges into index array int i =0; int j =0; for (i = 0; i < 5; i++) { index[i] = sizeof(topology[i]) / sizeof(int); for (j = 0; j < index[i]; j++) { edges[i][j] = topology[i][j]; } } // Display topology for each process for (i = 0; i < size; i++) { if (rank == i) { printf("Process %d has %d neighbors: ", i, index[i]); for (j = 0; j < index[i]; j++) { printf("%d ", edges[i][j]); } printf("n"); } MPI_Barrier(MPI_COMM_WORLD); } MPI_Finalize(); return 0; } MPI Functions:
  • 2. #include <mpi.h> #include <stdio.h> int main(int argc, char** argv) { int rank, size; MPI_Init(&argc, &argv); // Initialize MPI MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Get the rank of the current process MPI_Comm_size(MPI_COMM_WORLD, &size); // Get the total number of processes int nnodes = 5; // Number of nodes in the topology int nedges = 8; // Number of edges in the topolofy // Index of the first edge for each node int index[5] = {2, 5, 6, 8, 9}; int edges[9] = {4, 1, 0, 2, 3, 1, 4, 0, 3}; // List of all edges MPI_Comm graph_comm; // Create a new communicator for the graph topology MPI_Graph_create(MPI_COMM_WORLD, nnodes, index, edges, 0, &graph_comm); // Create the graph topology int count; // Number of neighbors int* neighbors; // Neighbor Ranks MPI_Graph_neighbors_count(graph_comm, rank, &count); // Get the number of neighbors for the current process neighbors = (int*) malloc(count * sizeof(int)); // Allocate memory for the array of neighbor ranks MPI_Graph_neighbors(graph_comm, rank, count, neighbors); // Get the neighbor ranks for the current process // Display process and the node in the topologies neighbors printf("Process %d has %d neighbors:", rank, count); int i; for (i = 0; i < count; i++) { printf(" %d", neighbors[i]); // Print the neighbor ranks } printf("n"); MPI_Finalize(); return 0; } ive provided my own code above in case that helps or makes it easier on you guys. My output isnt quite right ive been at it for a while if someone could fix the output and explain it to me id be very happy :) 4. Use Graph topology to create following one. Once you create your topology, use one process (e.g., process 0 ) to display the number of neighbors and its neighbors at each node (i.e., process). Use following two methods to check your topology. (20 points) i) Use two arrays, index and edges, to display number of neighbors and its neighbors for each node. ii) Use two functions in MPI, "MPI Graph neighbors count" and "MPI Graph neighbors". llinn@scholar-fe06: /470 $
  • 3. mpirun -n 5 ./hmwk5q4-b Process 0 has 2 neighbors: 41 Process 1 has 3 neighbors: 023 Process 2 has 1 neighbors: 1 Process 3 has 2 neighbors: 40