<commit_before>#include "cengpar.h"
#include "engpar_support.h"
#include "ngraph.h"
#include "engpar.h"

void cengpar_initialize() {
  EnGPar_Initialize();
}

void cengpar_finalize() {
  EnGPar_Finalize();
}

void cengpar_setftncommunicator(MPI_Fint fcomm) {
  MPI_Comm comm = MPI_Comm_f2c(fcomm);
  PCU_Switch_Comm(comm);
}

ngraph cengpar_createEmptyGraph() {
  agi::Ngraph* ng = agi::createEmptyGraph();
  return (ngraph)ng;
}

void cengpar_constructVerts(ngraph g, bool isHg,
    agi::gid_t* verts, agi::wgt_t* weights, int nverts) {
  agi::Ngraph* ng = (agi::Ngraph*)g;
  std::vector<agi::gid_t> v(verts, verts + nverts);
  std::vector<agi::wgt_t> w(weights, weights + nverts);
  ng->constructVerts(isHg,v,w);
}

void cengpar_constructEdges(ngraph g, agi::gid_t* edges,
    agi::lid_t* degs, agi::wgt_t* weights,
    agi::gid_t* pins, int nedges, int npins) {
  agi::Ngraph* ng = (agi::Ngraph*)g;
  std::vector<agi::gid_t> e(edges, edges + nedges);
  std::vector<agi::lid_t> d(degs, degs + nedges);
  std::vector<agi::wgt_t> w(weights, weights + nedges);
  std::vector<agi::gid_t> p(pins, pins + npins);
  ng->constructEdges(e,d,p,w);
}

void cengpar_constructGhosts(ngraph g, agi::gid_t* verts, agi::part_t* owners,
    int nghosts) {
  agi::Ngraph* ng = (agi::Ngraph*)g;
  std::unordered_map<agi::gid_t,agi::part_t> ghosts;
  for(int i=0; i<nghosts; i++)
    ghosts[verts[i]] = owners[i];
  ng->constructGhosts(ghosts);
}

void cengpar_checkValidity(ngraph g) {
  agi::Ngraph* ng = (agi::Ngraph*)g;
  agi::checkValidity(ng);
}

void cengpar_destroyGraph(ngraph g) {
  agi::Ngraph* ng = (agi::Ngraph*)g;
  agi::destroyGraph(ng);
}

void cengpar_balanceVertices(ngraph g, double tol, double stepfactor, int verbosity) {
  agi::Ngraph* ng = (agi::Ngraph*)g;
  agi::Balancer* b = engpar::makeVtxBalancer(ng, stepfactor, verbosity);
  b->balance(tol);
}

void cengpar_getPartition(ngraph g, agi::gid_t* verts,
    agi::part_t* parts, int nverts) {
  agi::Ngraph* ng = (agi::Ngraph*)g;
  assert(ng);
  agi::PartitionMap* ptn = ng->getPartition();
  assert( (int)ptn->size() == nverts );
  agi::PartitionMap::iterator itr;
  int i=0;
  for (itr=ptn->begin();itr!=ptn->end();itr++) {
    verts[i] = itr->first;
    parts[i] = itr->second;
    i++;
  }<commit_msg>Plug leaks in fortran interface<commit_after>#include "cengpar.h"
#include "engpar_support.h"
#include "ngraph.h"
#include "engpar.h"

void cengpar_initialize() {
  EnGPar_Initialize();
}

void cengpar_finalize() {
  EnGPar_Finalize();
}

void cengpar_setftncommunicator(MPI_Fint fcomm) {
  MPI_Comm comm = MPI_Comm_f2c(fcomm);
  PCU_Switch_Comm(comm);
}

ngraph cengpar_createEmptyGraph() {
  agi::Ngraph* ng = agi::createEmptyGraph();
  return (ngraph)ng;
}

void cengpar_constructVerts(ngraph g, bool isHg,
    agi::gid_t* verts, agi::wgt_t* weights, int nverts) {
  agi::Ngraph* ng = (agi::Ngraph*)g;
  std::vector<agi::gid_t> v(verts, verts + nverts);
  std::vector<agi::wgt_t> w(weights, weights + nverts);
  ng->constructVerts(isHg,v,w);
}

void cengpar_constructEdges(ngraph g, agi::gid_t* edges,
    agi::lid_t* degs, agi::wgt_t* weights,
    agi::gid_t* pins, int nedges, int npins) {
  agi::Ngraph* ng = (agi::Ngraph*)g;
  std::vector<agi::gid_t> e(edges, edges + nedges);
  std::vector<agi::lid_t> d(degs, degs + nedges);
  std::vector<agi::wgt_t> w(weights, weights + nedges);
  std::vector<agi::gid_t> p(pins, pins + npins);
  ng->constructEdges(e,d,p,w);
}

void cengpar_constructGhosts(ngraph g, agi::gid_t* verts, agi::part_t* owners,
    int nghosts) {
  agi::Ngraph* ng = (agi::Ngraph*)g;
  std::unordered_map<agi::gid_t,agi::part_t> ghosts;
  for(int i=0; i<nghosts; i++)
    ghosts[verts[i]] = owners[i];
  ng->constructGhosts(ghosts);
}

void cengpar_checkValidity(ngraph g) {
  agi::Ngraph* ng = (agi::Ngraph*)g;
  agi::checkValidity(ng);
}

void cengpar_destroyGraph(ngraph g) {
  agi::Ngraph* ng = (agi::Ngraph*)g;
  agi::destroyGraph(ng);
}

void cengpar_balanceVertices(ngraph g, double tol, double stepfactor, int verbosity) {
  agi::Ngraph* ng = (agi::Ngraph*)g;
  agi::Balancer* b = engpar::makeVtxBalancer(ng, stepfactor, verbosity);
  b->balance(tol);
  delete b;
}

void cengpar_getPartition(ngraph g, agi::gid_t* verts,
    agi::part_t* parts, int nverts) {
  agi::Ngraph* ng = (agi::Ngraph*)g;
  assert(ng);
  agi::PartitionMap* ptn = ng->getPartition();
  assert( (int)ptn->size() == nverts );
  agi::PartitionMap::iterator itr;
  int i=0;
  for (itr=ptn->begin();itr!=ptn->end();itr++) {
    verts[i] = itr->first;
    parts[i] = itr->second;
    i++;
  }
  delete ptn;
{'fraction_non_alphanumeric': 0.17907180385288968, 'fraction_numerical': 0.0013134851138353765, 'mean_word_length': 5.517831669044223, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1741624', 'n_tokens_mistral': 2002, 'n_tokens_neox': 1922, 'n_words': 346}