Skip to content
Snippets Groups Projects
Commit 986729ea authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Add code to dump METIS graph

parent c123d484
No related branches found
No related tags found
1 merge request!61 METIS fixes
/*******************************************************************************
* This file is part of SWIFT.
* Coypright (c) 2013 Matthieu Schaller (matthieu.schaller@durham.ac.uk),
* Pedro Gonnet (pedro.gonnet@durham.ac.uk).
* Copyright (c) 2013- 2015:
* Matthieu Schaller (matthieu.schaller@durham.ac.uk),
* Pedro Gonnet (pedro.gonnet@durham.ac.uk),
* Peter W. Draper (p.w.draper@durham.ac.uk).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
......@@ -20,8 +22,10 @@
#include <stdio.h>
#include "config.h"
#include "const.h"
#include "part.h"
#include "debug.h"
/**
* @brief Looks for the particle with the given id and prints its information to
......@@ -98,3 +102,86 @@ void printParticle_single(struct part *p) {
p->rho_dh, p->density.div_v, p->u, p->force.u_dt, p->force.balsara,
p->force.POrho2, p->force.v_sig, p->dt);
}
#ifdef HAVE_METIS
/**
* @brief Dump the METIS graph in standard format to stdout
*
* @param nvtxs the number of vertices
* @param ncon the number vertex weights
* @param xadj first part of adjacency info
* @param adjncy second part of adjacency info
* @param vwgt weights of vertices
* @param vsize size of vertices
* @param adjwgt weights of edges
*/
void printMETISGraph(idx_t nvtxs, idx_t ncon, idx_t *xadj, idx_t *adjncy,
idx_t *vwgt, idx_t *vsize, idx_t *adjwgt) {
idx_t i;
idx_t j;
int hasvwgt = 0;
int hasewgt = 0;
int hasvsize = 0;
/* Check for vwgt, vsize and adjwgt values. */
if (vwgt) {
for (i = 0; i < nvtxs * ncon; i++) {
if (vwgt[i] != 1) {
hasvwgt = 1;
break;
}
}
}
if (vsize) {
for (i = 0; i < nvtxs; i++) {
if (vsize[i] != 1) {
hasvsize = 1;
break;
}
}
}
if (adjwgt) {
for (i = 0; i < xadj[nvtxs]; i++) {
if (adjwgt[i] != 1) {
hasewgt = 1;
break;
}
}
}
/* Write the header line. */
printf("METIS: ");
printf("%" PRIDX " %" PRIDX, nvtxs, xadj[nvtxs] / 2);
if (hasvwgt || hasvsize || hasewgt) {
printf(" %d%d%d", hasvsize, hasvwgt, hasewgt);
if (hasvwgt) {
printf(" %d", (int)ncon);
}
}
/* Write the rest of the graph. */
for (i = 0; i < nvtxs; i++) {
printf("\nMETIS: ");
if (hasvsize) {
printf(" %" PRIDX, vsize[i]);
}
if (hasvwgt) {
for (j = 0; j < ncon; j++) {
printf(" %" PRIDX, vwgt[i * ncon + j]);
}
}
for (j = xadj[i]; j < xadj[i + 1]; j++) {
printf(" %" PRIDX, adjncy[j] + 1);
if (hasewgt) {
printf(" %" PRIDX, adjwgt[j]);
}
}
}
printf("\n");
}
#endif
......@@ -27,4 +27,10 @@ void printParticle(struct part *parts, long long int i, int N);
void printgParticle(struct gpart *parts, long long int i, int N);
void printParticle_single(struct part *p);
#ifdef HAVE_METIS
#include "metis.h"
void printMETISGraph(idx_t nvtxs, idx_t ncon, idx_t *xadj, idx_t *adjncy,
idx_t *vwgt, idx_t *vsize, idx_t *adjwgt);
#endif
#endif /* SWIFT_DEBUG_H */
......@@ -540,11 +540,16 @@ void engine_repartition(struct engine *e) {
/* Call METIS. */
idx_t one = 1, idx_nr_cells = nr_cells, idx_nr_nodes = nr_nodes;
idx_t objval;
/* Dump graph in METIS format */
printMETISGraph(idx_nr_cells, one, offsets, inds, weights_v, NULL, weights_e);
if (METIS_PartGraphRecursive(&idx_nr_cells, &one, offsets, inds, weights_v,
NULL, weights_e, &idx_nr_nodes, NULL, NULL,
options, &objval, nodeIDs) != METIS_OK)
error("Call to METIS_PartGraphKway failed.");
/* Dump the 3d array of cell IDs. */
/* printf( "engine_repartition: nodeIDs = reshape( [" );
for ( i = 0 ; i < cdim[0]*cdim[1]*cdim[2] ; i++ )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment