Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/KarypisLab/ParMETIS/llms.txt

Use this file to discover all available pages before exploring further.

ParMETIS_V3_AdaptiveRepart repartitions a distributed graph whose load has changed since the last partition — for example, after mesh refinement or when computational work per vertex varies over time. Rather than optimizing edge cut alone, it balances a combined objective that accounts for both inter-process communication and the cost of moving vertices to new partitions. The ipc2redist parameter controls this tradeoff: lower values prioritize minimizing vertex movement, while higher values prioritize minimizing the edge cut of the new partition.
int ParMETIS_V3_AdaptiveRepart(
    idx_t *vtxdist, idx_t *xadj, idx_t *adjncy, idx_t *vwgt,
    idx_t *vsize, idx_t *adjwgt, idx_t *wgtflag, idx_t *numflag, idx_t *ncon,
    idx_t *nparts, real_t *tpwgts, real_t *ubvec, real_t *ipc2redist,
    idx_t *options, idx_t *edgecut, idx_t *part, MPI_Comm *comm);

Parameters

vtxdist
idx_t*
Distribution of vertices across processes. vtxdist[i] is the global index of the first vertex on process i. Size npes + 1; must be identical on all processes.
xadj
idx_t*
Local adjacency row pointers in CSR format. Size local_nvtxs + 1.
adjncy
idx_t*
Local adjacency column indices in CSR format. Size xadj[local_nvtxs].
vwgt
idx_t*
Vertex weights. ncon values per vertex in interleaved order. May be NULL when bit 1 of wgtflag is 0.
vsize
idx_t*
Per-vertex communication size used to estimate redistribution cost. When a vertex moves to a new partition, its vsize contributes to the redistribution penalty in the objective function. May be NULL, in which case unit sizes are assumed.
adjwgt
idx_t*
Edge weights, one value per entry in adjncy. May be NULL when bit 0 of wgtflag is 0.
wgtflag
idx_t*
Bitmask controlling which weights are used. 0 = no weights, 1 = edge weights only, 2 = vertex weights only, 3 = both.
numflag
idx_t*
Indexing convention. 0 for C-style 0-based indexing; 1 for Fortran-style 1-based indexing.
ncon
idx_t*
Number of balancing constraints per vertex.
nparts
idx_t*
Desired number of partitions after repartitioning.
tpwgts
real_t*
Target partition weights. Array of nparts * ncon values. Values for each constraint must sum to 1.0. Pass NULL for equal-weight partitions.
ubvec
real_t*
Per-constraint imbalance tolerance. Array of ncon values greater than 1.0.
ipc2redist
real_t*
Tradeoff parameter between inter-process communication cost and redistribution cost. Lower values (e.g., 0.001) minimize vertex movement; higher values (e.g., 1000.0) optimize partition quality as if starting from scratch. Typical values range from 1.0 to 1000.0.
options
idx_t*
Algorithm options. If options[0] = 0, all defaults are used. If options[0] = 1, options[PMV3_OPTION_DBGLVL] (index 1) sets the debug level and options[PMV3_OPTION_SEED] (index 2) sets the random seed.
edgecut
idx_t*
Output. Total weight of edges crossing partition boundaries after repartitioning.
part
idx_t*
Input and output. On entry, contains the current partition assignment for each local vertex. On return, contains the new partition assignment. Caller must allocate at least local_nvtxs elements.
comm
MPI_Comm*
Pointer to the MPI communicator covering all participating processes.

Return value

Returns METIS_OK (1) on success. Any other value indicates an error.

Usage example

#include <parmetis.h>

int main(int argc, char *argv[]) {
    MPI_Init(&argc, &argv);
    MPI_Comm comm = MPI_COMM_WORLD;

    int npes, rank;
    MPI_Comm_size(comm, &npes);
    MPI_Comm_rank(comm, &rank);

    idx_t local_nvtxs = 10;
    idx_t vtxdist[npes + 1];
    for (int i = 0; i <= npes; i++) vtxdist[i] = i * local_nvtxs;

    idx_t xadj[local_nvtxs + 1];
    idx_t adjncy[/* nnz */];

    /* Assume part[] holds the current partition assignment */
    idx_t part[local_nvtxs];

    idx_t wgtflag = 0;
    idx_t numflag = 0;
    idx_t ncon    = 1;
    idx_t nparts  = npes;
    real_t tpwgts[nparts];
    for (int i = 0; i < nparts; i++) tpwgts[i] = 1.0f / nparts;
    real_t ubvec       = 1.05f;
    real_t ipc2redist  = 100.0f; /* favor quality over minimizing movement */
    idx_t options[3]   = {0, 0, 0};
    idx_t edgecut;

    int ret = ParMETIS_V3_AdaptiveRepart(
        vtxdist, xadj, adjncy,
        NULL,    /* no vertex weights */
        NULL,    /* no vertex sizes   */
        NULL,    /* no edge weights   */
        &wgtflag, &numflag, &ncon, &nparts,
        tpwgts, &ubvec, &ipc2redist,
        options, &edgecut, part, &comm);

    if (ret != METIS_OK) { /* handle error */ }

    MPI_Finalize();
    return 0;
}

Build docs developers (and LLMs) love