mpi
Procestopologieën
Zoeken…
Creatie en communicatie van grafiektopologie
Creëert een grafische topologie op een verdeelde manier zodat elk knooppunt zijn buren definieert. Elk knooppunt communiceert zijn rang onder buren met MPI_Neighbor_allgather
.
#include <mpi.h>
#include <stdio.h>
#define nnode 4
int main()
{
MPI_Init(NULL, NULL);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int source = rank;
int degree;
int dest[nnode];
int weight[nnode] = {1, 1, 1, 1};
int recv[nnode] = {-1, -1, -1, -1};
int send = rank;
// set dest and degree.
if (rank == 0)
{
dest[0] = 1;
dest[1] = 3;
degree = 2;
}
else if(rank == 1)
{
dest[0] = 0;
degree = 1;
}
else if(rank == 2)
{
dest[0] = 3;
dest[1] = 0;
dest[2] = 1;
degree = 3;
}
else if(rank == 3)
{
dest[0] = 0;
dest[1] = 2;
dest[2] = 1;
degree = 3;
}
// create graph.
MPI_Comm graph;
MPI_Dist_graph_create(MPI_COMM_WORLD, 1, &source, °ree, dest, weight, MPI_INFO_NULL, 1, &graph);
// send and gather rank to/from neighbors.
MPI_Neighbor_allgather(&send, 1, MPI_INT, recv, 1, MPI_INT, graph);
printf("Rank: %i, recv[0] = %i, recv[1] = %i, recv[2] = %i, recv[3] = %i\n", rank, recv[0], recv[1], recv[2], recv[3]);
MPI_Finalize();
return 0;
}
Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow