{"id":32139449,"url":"https://github.com/chiao45/mgmetis","last_synced_at":"2026-02-18T20:32:45.431Z","repository":{"id":48118124,"uuid":"214655756","full_name":"chiao45/mgmetis","owner":"chiao45","description":"METIS partitioner for mesh and graph","archived":false,"fork":false,"pushed_at":"2021-08-05T20:53:18.000Z","size":476,"stargazers_count":18,"open_issues_count":5,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-21T05:48:14.758Z","etag":null,"topics":["graph-algorithms","mesh","metis","partitioning-algorithms","scientific-computing"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chiao45.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-12T13:55:03.000Z","updated_at":"2025-10-09T13:17:20.000Z","dependencies_parsed_at":"2022-08-12T19:00:43.072Z","dependency_job_id":null,"html_url":"https://github.com/chiao45/mgmetis","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chiao45/mgmetis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chiao45%2Fmgmetis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chiao45%2Fmgmetis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chiao45%2Fmgmetis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chiao45%2Fmgmetis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chiao45","download_url":"https://codeload.github.com/chiao45/mgmetis/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chiao45%2Fmgmetis/sbom","scorecard":{"id":277284,"data":{"date":"2025-08-11","repo":{"name":"github.com/chiao45/mgmetis","commit":"d715ca50d119d51643880f9ce9b318cbd24297e3"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 1/15 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"11 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2018-34 / GHSA-2fc2-6r4j-p65h","Warn: Project is vulnerable to: PYSEC-2021-856 / GHSA-5545-2q6w-2gh6","Warn: Project is vulnerable to: PYSEC-2019-108 / GHSA-9fq2-x9r6-wfmf","Warn: Project is vulnerable to: PYSEC-2018-33 / GHSA-cw6w-4rcx-xphc","Warn: Project is vulnerable to: PYSEC-2021-857 / GHSA-f7c7-j99h-c22f","Warn: Project is vulnerable to: GHSA-fpfv-jqm9-f5jm","Warn: Project is vulnerable to: PYSEC-2017-1 / GHSA-frgw-fgh6-9g52","Warn: Project is vulnerable to: PYSEC-2013-22 / GHSA-27x4-j476-jp5f","Warn: Project is vulnerable to: PYSEC-2025-49 / GHSA-5rjg-fvgr-3xxf","Warn: Project is vulnerable to: GHSA-cx63-2mw6-8hw5","Warn: Project is vulnerable to: PYSEC-2022-43012 / GHSA-r9hx-vwmv-q579"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 18 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T14:50:14.770Z","repository_id":48118124,"created_at":"2025-08-17T14:50:14.770Z","updated_at":"2025-08-17T14:50:14.770Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29594259,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T18:54:29.675Z","status":"ssl_error","status_checked_at":"2026-02-18T18:50:50.517Z","response_time":162,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graph-algorithms","mesh","metis","partitioning-algorithms","scientific-computing"],"created_at":"2025-10-21T05:48:15.557Z","updated_at":"2026-02-18T20:32:45.418Z","avatar_url":"https://github.com/chiao45.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"MGMETIS---Mesh \u0026 Graph METIS Partitioning\n=========================================\n\n.. image:: https://travis-ci.org/chiao45/mgmetis.svg?branch=master\n    :target: https://travis-ci.org/chiao45/mgmetis\n.. image:: https://img.shields.io/pypi/v/mgmetis.svg?branch=master\n    :target: https://pypi.org/project/mgmetis/\n.. image:: https://img.shields.io/pypi/pyversions/mgmetis.svg?style=flat-square\n    :target: https://pypi.org/project/mgmetis/\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/ambv/black\n\nIntroduction\n------------\n\n*mgmetis* is a mesh and graph Partitioning suite wrapped on top of\n`METIS \u0026 ParMETIS \u003chttp://glaros.dtc.umn.edu/gkhome/views/metis\u003e`_. It targets\nat intermediate level of package developers who work in, e.g., finite element\nlibraries.\n\n*mgmetis* provides all functionalities from original METIS/ParMETIS via 1) a\n`Cython \u003chttps://cython.org/\u003e`_ interface and 2) a native Python interface\nthrough ``ctypes``.\n\nInstallation\n------------\n\n*mgmetis* can be installed via ``pip``, i.e.,\n\n.. code:: console\n\n    $ pip3 install mgmetis --user\n\nIf you have MPI and `mpi4py \u003chttps://bitbucket.org/mpi4py/mpi4py/src/master/\u003e`_\ninstalled, then the parallel components will be built automatically. Note that\nmpi4py is **NOT** an installation dependency.\n\nExamples\n--------\n\nIt's worth noting that *mgmetis* simply wraps around original METIS interfaces.\n*mgmetis* doesn't have complicated data structures for graphs and meshes,\neverything is passed in as arrays as per CSR format. The variable names are\npreserved as what they are in the original documentation. For more information,\nplease refer to http://glaros.dtc.umn.edu/gkhome/metis/metis/download and\nhttp://glaros.dtc.umn.edu/gkhome/metis/parmetis/download for METIS and ParMETIS\noriginal documentation PDF files, respectively.\n\nPython Mode\n```````````\n\nFor graph Partitioning, either *multilevel recursive bisection* or\n*multilevel k-way partitioning* methods, the interfaces are exactly the same.\nThe mandatory parameters are ``nparts`` (number of partitions), ``xadj`` (the\nstarting positions of adjacent list) and ``adjncy`` (the compressed adjacent\nlist).\n\nGive a a directed graph based on the following structure::\n\n    0---1---2\n    |   |   |\n    3---4---5\n    |   |   |\n    6---7---8\n\nWe can have the set up a simple graph representation, which looks like\n\n.. code-block:: python\n\n    \u003e\u003e\u003e graph = {\n    ...    0: [1, 3],\n    ...    1: [0, 2, 4],\n    ...    2: [1, 5],\n    ...    3: [0, 4, 6],\n    ...    4: [1, 3, 5, 7],\n    ...    5: [2, 4, 8],\n    ...    6: [3, 7],\n    ...    7: [4, 6, 8],\n    ...    8: [5, 7],\n    ... }\n\n\nWe can then convert it into CSR graph\n\n.. code-block:: python\n\n    \u003e\u003e\u003e xadj = [0]\n    \u003e\u003e\u003e for edges in graph.values():\n    ...     xadj.append(xadj[-1]+len(edges))\n    ...\n    \u003e\u003e\u003e xadj\n    [0, 2, 5, 7, 10, 14, 17, 19, 22, 24]\n    \u003e\u003e\u003e adjncy = [node for edges in graph.values() for node in edges]\n\nThen a partition of 2 with recursive algorithm can be simply done via\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from mgmetis import metis\n    \u003e\u003e\u003e objval, part = metis.part_graph_recursive(2, xadj, adjncy)\n    \u003e\u003e\u003e part\n    array([0, 0, 1, 0, 0, 1, 1, 1, 1])\n\nNotice that the structure in this example can also be viewed as a mesh with 12\nbar cells, of which the user may want to determine a element-wise partition.\n\n.. code-block:: python\n\n    cells = [\n    ...     [0, 1],\n    ...     [1, 2],\n    ...     [3, 4],\n    ...     [4, 5],\n    ...     [6, 7],\n    ...     [7, 8],\n    ...     [0, 3],\n    ...     [1, 4],\n    ...     [2, 5],\n    ...     [3, 6],\n    ...     [4, 7],\n    ...     [5, 8],\n    ... ]\n\nThen, partitoning the mesh into 2 components can be done via `part_mesh_dual`\n\n.. code-block:: python\n\n    \u003e\u003e\u003e objval, epart, npart = metis.part_mesh_dual(2, cells)\n    \u003e\u003e\u003e epart\n    array([0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1])\n\nFor other supported advanced features, such as weights, please consult the\nMETIS documentation. All the arguments are supported via keyword inputs. Here,\nwe further demonstrate how to customize options, a.k.a. control parameters, in\nMETIS. The parameters in metis are specified via a fixed length 40 integer\narray.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e opts = metis.get_default_options()\n    \u003e\u003e\u003e opts\n    Options([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n             -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n             -1, -1, -1, -1, -1, -1, -1, -1], dtype=int32)\n\nIf you are familiar with METIS, you can directly work with the parameters.\n*mgmetis* implements a helper module ``mgmetis.enums`` to help the user work\nwith control parameters. Let's say the user has a Fortran-based index graph\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from mgmetis.enums import OPTION\n    \u003e\u003e\u003e opts[OPTION.NUMBERING] = 1\n    \u003e\u003e\u003e xadj = [x + 1 for x in xadj]\n    \u003e\u003e\u003e adjncy = [x + 1 for x in adjncy]\n    \u003e\u003e\u003e objval, part = metis.part_graph_recursive(2, xadj, adjncy, options=opts)\n    \u003e\u003e\u003e part\n    array([1, 1, 2, 1, 1, 2, 2, 2, 2])\n\n.. note:: *mgmetis* can automatically handle Fortran index.\n\n``ctypes`` Mode\n```````````````\n\nA powerful feature of *mgmetis* is that it allows the user to directly work\nwith the underlying C functions through ``ctypes``. However, by dealing with\nforeign C interfaces, the user needs to explicitly ensure the type consistency.\n\n*mgmetis* supports both 32-bit and 64-bit integer builds of METIS. The original\nMETIS functions all have prefix ``METIS_``, whereas in *mgmetis* ``ctypes``\nmodule, the prefix is trimmed out. Let's see the following example to see how\nto use the ``ctypes`` interface.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import numpy as np\n    \u003e\u003e\u003e xadj = np.asarray(xadj)  # from list of ints, the dtype is int64\n    \u003e\u003e\u003e adjncy = np.asarray(adjncy)\n    \u003e\u003e\u003e part = np.empty(xadj.size - 1, dtype=int) # output\n    \u003e\u003e\u003e opts = np.assarray(opts, dtype=int)\n\nRecall that the graph partitioning routine takes all arguments as their\nreferences. This can be done via ``ctypes``\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import ctypes as c\n    \u003e\u003e\u003e nv = c.c_int64(part.size)\n    \u003e\u003e\u003e ncon = c.c_int64(1)\n    \u003e\u003e\u003e objval = c.c_int64(0)  # output\n    \u003e\u003e\u003e nparts = c.c_int64(2)\n    \u003e\u003e\u003e xadj_ptr = xadj.ctypes.data_as(c.POINTER(c.c_int64))\n    \u003e\u003e\u003e adj_ptr = adjncy.ctypes.data_as(c.POINTER(c.c_ind64))\n    \u003e\u003e\u003e opts_ptr = opts.ctypes.data_as(c.POINTER(c.c_int64))\n    \u003e\u003e\u003e part_ptr = part.ctypes.data_as(c.POINTER(c.c_int64))  # output address\n\nWe now need to access the ctype interface in *mgmetis*\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from mgmetis.metis import libmetis64  # libmetis for 32bit int\n    \u003e\u003e\u003e libmetis64.PartGraphRecursive(\n    ...     c.byref(nv),\n    ...     c.byref(ncon),\n    ...     xadj_ptr,\n    ...     adj_ptr,\n    ...     None, # NULL\n    ...     None,\n    ...     None,\n    ...     c.byref(nparts),\n    ...     None,\n    ...     None,\n    ...     opts_ptr,\n    ...     c.byref(objval),\n    ...     part_ptr,\n    ... )\n\nFor more details for ``ctypes``, please refer to https://docs.python.org/3.8/library/ctypes.html.\nAlso, take a look at `np.ndarray.ctypes \u003chttps://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.ctypes.html\u003e`_.\n\nEnable METIS in Cython\n```````````````````````\n\nEach of the METIS routine has a Cython interface, whose naming convention is\nsamilar as it's in ``ctypes`` mode. *mgmetis* resolves the issues regarding\nlinking to METIS. In addition, each of the Cython function is defined with\n``nogil`` specifier.\n\nThe following code shows how to access the ``METIS_PartGraphRecursive``\n\n.. code-block:: cython\n\n    cimport mgmetis.libmetis as metis  # 32 bit\n    # then each of the function in METIS public domain has a Cython interface\n    # without prefix METIS_\n    cdef int ret = metis.PartGraphRecursive(...)\n    if ret != metis.OK:\n        raise ValueError\n\nWhen you compile your Cython code, you don't need to worry about linking to\nMETIS, Python will load the correct symbol in runtime.\n\nWork with MPI\n`````````````\n\nThe native Python mode supports parallel partitioning of a static graph or\nmesh. The underlying routines are:\n\n1. ``ParMETIS_V3_PartKway``,\n2. ``ParMETIS_V3_PartGeomKway``,\n3. ``ParMETIS_V3_PartGeom``, and\n4. ``ParMETIS_V3_PartMeshKway``.\n\nTheir usage is similar to the serial version, please take a look at the unit\ntesting scripts.\n\nA complete support of ParMETIS can be done (for now) via either ``ctypes``\nmode or Cython mode. For ``ctypes`` mode\n\n.. code-block:: python\n\n    from mgmetis.parmetis import libparmetis  # libparmetis64 for 64bit\n    help(libparmetis)\n\nand for the Cython mode\n\n.. code-block:: cython\n\n    cimport mgmetis.parmetis as parmetis  # mgmetis.parmetis64 for 64 bit\n    cdef int ret = parmetis.PartKway(...)\n\nNotice that for Cython mode, you will need to access *mpi4py* Cython interface.\nIt will, then, require you to add its path during specifying ``Extension``, and\nthe compiler needs to be set to *mpicc*.\n\nLicense\n-------\n\n*mgmetis* is considerred as a wrapper of METIS, and it is distributed under MIT\nlicense. Users should also refer to http://glaros.dtc.umn.edu/gkhome/views/metis\nfor the licenses of METIS and ParMETIS.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchiao45%2Fmgmetis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchiao45%2Fmgmetis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchiao45%2Fmgmetis/lists"}