Skip to content

Instantly share code, notes, and snippets.

@cwsmith
Created September 19, 2012 13:16
Show Gist options
  • Save cwsmith/3749622 to your computer and use it in GitHub Desktop.
Save cwsmith/3749622 to your computer and use it in GitHub Desktop.
luby mis test driver
#include <stdio.h>
#include <set>
#include <vector>
#include "mis.h"
#include "mpi.h"
using std::set;
using std::vector;
/**
* @brief each process creates a net with itself and its rank-1 and rank+1 neighbors, the MIS should be of size floor(numProcs/3)
* @remark each process is adjacent to rank-1 and rank+1
* @param rank (In) mpi process rank
* @param totNumParts (In) number of parts in the mesh
* @param numParts (In) number of parts per process
* @return 0 on success, non-zero otherwise
*/
int test_EastWestNet_EastWestAdjacent(const int rank, const int totNumParts, const int numParts) {
partInfo part;
part.id = rank;
int prev = rank-1;
if (rank==0) {
prev = totNumParts-1;
}
part.adjPartIds.push_back(prev);
part.net.push_back(prev);
int next = rank+1;
if (rank==totNumParts-1) {
next = 0;
}
part.adjPartIds.push_back(next);
part.net.push_back(next);
part.net.push_back(rank); // needed? HERE
vector<partInfo> parts;
parts.push_back(part);
vector<int> maximalIndSet;
int ierr = mis(rank, totNumParts, parts, maximalIndSet); // INF loops HERE
printf("DEBUG [%3d] isInIS=%3d\n", rank, maximalIndSet.size());
int misLocalSize=maximalIndSet.size();
int sizeIS = 0;
MPI_Allreduce(&misLocalSize, &sizeIS, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
if ( sizeIS < totNumParts/3 ) {
return 1;
} else {
if ( 0 == rank ) {
printf("\n\nDEBUG |independent set| = %d\n", sizeIS);
}
return 0;
}
}
int main(int argc, char** argv) {
MPI_Init(&argc, &argv);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int commSize;
MPI_Comm_size(MPI_COMM_WORLD, &commSize);
if ( 0 == rank ) {
printf("|V| = %d\n", commSize);
}
if ( 0 == rank ) {
printf("running test_EastWestNet_EastWestAdjacent...\n");
}
const int numParts = 1;
int ierr = test_EastWestNet_EastWestAdjacent(rank, commSize, numParts);
if( ierr != 0 ) {
if (0 == rank) {
printf("failed\n");
}
} else {
if (0 == rank) {
printf("passed.\n");
}
}
MPI_Finalize();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment