diff --git a/src/debug.c b/src/debug.c index d55d5443457fe3be41f6d1983a1eca8d7ab99f3c..9b50fcee408db8dd4c9724cf47970306687182dd 100644 --- a/src/debug.c +++ b/src/debug.c @@ -1,7 +1,9 @@ /******************************************************************************* * 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 diff --git a/src/debug.h b/src/debug.h index 5c9eb7b32db8ef5d07d97b867c68ec09b848e337..a78b67dab734c836edc0d9a8516d819f5dcc689d 100644 --- a/src/debug.h +++ b/src/debug.h @@ -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 */ diff --git a/src/engine.c b/src/engine.c index c4f5dccad5c829efd3b1b50211c4f6a06a28e198..4aec02a8b4a6ffe952dbdb007dc0b0363c59993a 100644 --- a/src/engine.c +++ b/src/engine.c @@ -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++ )