<commit_before>#include <apfMesh2.h>
#include <cassert>
#include <gmi_mesh.h>
#include <apfMDS.h>
#include <apf.h>
#include <cstdlib>
#include <stdint.h>
#include <apfNumbering.h>
#include <cstring>
#include <engpar_support.h>
#include <ngraph.h>

typedef std::vector<apf::MeshEntity*> BL_Verts;

void collapseBoundaryLayer(apf::Mesh*, std::vector<BL_Verts>&);
int numberStacksAndVerts(apf::Mesh*, const std::vector<BL_Verts>&, apf::MeshTag*&);
void gatherGraphVertices(apf::Mesh*, const std::vector<BL_Verts>&, apf::MeshTag*,
                         agi::lid_t, agi::gid_t*&, agi::wgt_t*&);
agi::lid_t gatherGraphEdges(apf::Mesh*, const std::vector<BL_Verts>&, apf::MeshTag*, int dim,
                            agi::gid_t*& edge_ids, agi::lid_t*& degs, agi::gid_t*& pins,
                            agi::wgt_t*&);

int main(int argc, char* argv[]) {
  MPI_Init(&argc, &argv);
  EnGPar_Initialize();
  if ( argc < 6 ) {
    if ( !PCU_Comm_Self() )
      printf("Usage: %s <model> <mesh> <output graph file> <Collapse BL [0/1]> <secondary_dimensions, ...>\n", argv[0]);
    EnGPar_Finalize();
    MPI_Finalize();
    assert(false);
  }

  gmi_register_mesh();
  apf::Mesh2* m = apf::loadMdsMesh(argv[1],argv[2]);

  bool collapseBL = atoi(argv[4]);
  std::vector<BL_Verts> bl_stacks;
  if (collapseBL) {
    collapseBoundaryLayer(m,bl_stacks);
  }

  printf("Number of stacks found: %lu\n",bl_stacks.size());

  //Create a tag to number vertices
  //All members of a stack have the same number (index of the array)
  apf::MeshTag* vert_ids;
  int num_verts = numberStacksAndVerts(m, bl_stacks, vert_ids);

  //Construct the vertices of the graph
  agi::gid_t* verts;
  agi::wgt_t* vert_weights;
  gatherGraphVertices(m, bl_stacks, vert_ids, num_verts, verts, vert_weights);
  agi::Ngraph* g = agi::createEmptyGraph();
  g->constructVerts(true, num_verts, verts, vert_weights);
  delete [] verts;
  delete [] vert_weights;

  //Construct the edges of the graph
  agi::gid_t* edge_ids;
  agi::lid_t* degs;
  agi::gid_t* pins;
  agi::wgt_t* edge_weights;
  for (int i = 5; i <argc; ++i) {
    int dimension = atoi(argv[i]);
    agi::lid_t num_edges = gatherGraphEdges(m, bl_stacks, vert_ids, dimension, edge_ids, degs,
                                            pins, edge_weights);
    g->constructEdges(num_edges, edge_ids, degs, pins, edge_weights);
    delete [] edge_ids;
    delete [] degs;
    delete [] pins;
    delete [] edge_weights;
  }
  //TODO: construct ghosts (for now only worrying about serial)
  agi::lid_t num_ghosts = 0;
  agi::gid_t* gids = NULL;
  agi::part_t* owners = NULL;
  g->constructGhosts(num_ghosts,gids,owners);

  agi::checkValidity(g);
  m->destroyNative();
  apf::destroyMesh(m);

  PCU_Barrier();
  if (!PCU_Comm_Self())<commit_msg>delete vertex count tag and write graph to file<commit_after>#include <apfMesh2.h>
#include <cassert>
#include <gmi_mesh.h>
#include <apfMDS.h>
#include <apf.h>
#include <cstdlib>
#include <stdint.h>
#include <apfNumbering.h>
#include <cstring>
#include <engpar_support.h>
#include <ngraph.h>

typedef std::vector<apf::MeshEntity*> BL_Verts;

void collapseBoundaryLayer(apf::Mesh*, std::vector<BL_Verts>&);
int numberStacksAndVerts(apf::Mesh*, const std::vector<BL_Verts>&, apf::MeshTag*&);
void gatherGraphVertices(apf::Mesh*, const std::vector<BL_Verts>&, apf::MeshTag*,
                         agi::lid_t, agi::gid_t*&, agi::wgt_t*&);
agi::lid_t gatherGraphEdges(apf::Mesh*, const std::vector<BL_Verts>&, apf::MeshTag*, int dim,
                            agi::gid_t*& edge_ids, agi::lid_t*& degs, agi::gid_t*& pins,
                            agi::wgt_t*&);

int main(int argc, char* argv[]) {
  MPI_Init(&argc, &argv);
  EnGPar_Initialize();
  if ( argc < 6 ) {
    if ( !PCU_Comm_Self() )
      printf("Usage: %s <model> <mesh> <output graph file> <Collapse BL [0/1]> <secondary_dimensions, ...>\n", argv[0]);
    EnGPar_Finalize();
    MPI_Finalize();
    assert(false);
  }

  gmi_register_mesh();
  apf::Mesh2* m = apf::loadMdsMesh(argv[1],argv[2]);

  bool collapseBL = atoi(argv[4]);
  std::vector<BL_Verts> bl_stacks;
  if (collapseBL) {
    collapseBoundaryLayer(m,bl_stacks);
  }

  printf("Number of stacks found: %lu\n",bl_stacks.size());

  //Create a tag to number vertices
  //All members of a stack have the same number (index of the array)
  apf::MeshTag* vert_ids;
  int num_verts = numberStacksAndVerts(m, bl_stacks, vert_ids);

  //Construct the vertices of the graph
  agi::gid_t* verts;
  agi::wgt_t* vert_weights;
  gatherGraphVertices(m, bl_stacks, vert_ids, num_verts, verts, vert_weights);
  agi::Ngraph* g = agi::createEmptyGraph();
  g->constructVerts(true, num_verts, verts, vert_weights);
  delete [] verts;
  delete [] vert_weights;

  //Construct the edges of the graph
  agi::gid_t* edge_ids;
  agi::lid_t* degs;
  agi::gid_t* pins;
  agi::wgt_t* edge_weights;
  for (int i = 5; i <argc; ++i) {
    int dimension = atoi(argv[i]);
    agi::lid_t num_edges = gatherGraphEdges(m, bl_stacks, vert_ids, dimension, edge_ids, degs,
                                            pins, edge_weights);
    g->constructEdges(num_edges, edge_ids, degs, pins, edge_weights);
    delete [] edge_ids;
    delete [] degs;
    delete [] pins;
    delete [] edge_weights;
  }
  //TODO: construct ghosts (for now only worrying about serial)
  agi::lid_t num_ghosts = 0;
  agi::gid_t* gids = NULL;
  agi::part_t* owners = NULL;
  g->constructGhosts(num_ghosts,gids,owners);

  m->destroyTag(vert_ids);

  agi::checkValidity(g);
  m->destroyNative();
  apf::destroyMesh(m);

  g->saveToFile(argv[3]);

  PCU_Barrier();
  if (!PCU_Comm_Self())
{'fraction_non_alphanumeric': 0.15633327411618406, 'fraction_numerical': 0.004085983300763901, 'mean_word_length': 4.013357079252003, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7187659', 'n_tokens_mistral': 2216, 'n_tokens_neox': 2127, 'n_words': 461}