<commit_before>#include <assert.h>
#include <PCU.h>
#include <apf.h>
#include <apfMesh.h>
#include <apfNumbering.h>
#include "parma_weights.h"
#include "parma_sides.h"
#include "parma_ghostOwner.h"

namespace {
  apf::MeshEntity* getOtherVtx(apf::Mesh* m,
      apf::MeshEntity* edge, apf::MeshEntity* vtx) {
    apf::Downward dwnVtx;
    int nDwnVtx = m->getDownward(edge,getDimension(m,edge)-1,dwnVtx);
    assert(nDwnVtx==2);
    return (dwnVtx[0] != vtx) ? dwnVtx[0] : dwnVtx[1];
  }

  bool isOwnedByPeer(apf::Mesh* m,apf::MeshEntity* v, int peer) {
    if( ! m->isShared(v) ) return false;
    return (parma::getOwner(m,v) == peer);
  }

  // vertex based BFS
  // return an array of vertex, edge and element weights
  // - no one needs faces... yet
  // the returned array needs to be deallocated
  double* runBFS(apf::Mesh* m, int layers, std::vector<apf::MeshEntity*> current,
      apf::MeshTag* visited, apf::MeshTag* wtag, int peer)
  {
    assert(layers>=0);
    const int elmDim = m->getDimension();
    double* weight = new double[4];
    for(unsigned int i=0; i<4; i++)
      weight[i] = 0;

    std::vector<apf::MeshEntity*> next;
    for (int i=1;i<=layers;i++) {
      // when i==1: current contains shared vertices
      //            owned by the peer that are not ghosted
      for (unsigned int j=0;j<current.size();j++) {
        apf::MeshEntity* vertex = current[j];
        apf::Up edges;
        m->getUp(vertex,edges);
        for (int k=0;k<edges.n;k++) {
          apf::MeshEntity* edge = edges.e[k];
          apf::MeshEntity* v = getOtherVtx(m,edge,vertex);
          //ghost vertices
          if (parma::isOwned(m, v) && !m->hasTag(v,visited)) {
            next.push_back(v);
            m->setIntTag(v,visited,&i);
            weight[0] += parma::getEntWeight(m,v,wtag);
          }
          //ghost edges
          if (parma::isOwned(m, edge) && !m->hasTag(edge,visited)) {
            weight[1] += parma::getEntWeight(m,edge,wtag);
            m->setIntTag(edge,visited,&i);
          }
        }
        //ghost elements
        apf::Adjacent elms;
        m->getAdjacent(vertex, elmDim, elms);
        for(size_t k=0; k<elms.size(); k++) {
          if (!m->hasTag(elms[k],visited)) {
            m->setIntTag(elms[k],visited,&i);
            weight[elmDim] += parma::getEntWeight(m,elms[k],wtag);
          }
        }
      }
      current=next;
      next.clear();
    }
    PCU_Debug_Print("ghostW peer %d vtx %f edge %f elm %f\n",
        peer, weight[0], weight[1], weight[elmDim]);
    return weight;
  }

  double ownedWeight(apf::Mesh* m, apf::MeshTag* w, int dim) {
    apf::MeshIterator* it = m->begin(dim);
    apf::MeshEntity* e;
    double entW = 0;
    double sum = 0;
    while ((e = m->iterate(it))) {
      assert(m->hasTag(e,w));
      if (parma::isOwned(m,e)) {
        m->getDoubleTag(e,w,&entW);
        sum += entW;
      }
    }
    m->end(it);
    return sum;
  }<commit_msg>get all the ghosted ents<commit_after>#include <assert.h>
#include <PCU.h>
#include <apf.h>
#include <apfMesh.h>
#include <apfNumbering.h>
#include "parma_weights.h"
#include "parma_sides.h"
#include "parma_ghostOwner.h"

namespace {
  bool isOwnedByPeer(apf::Mesh* m,apf::MeshEntity* v, int peer) {
    if( ! m->isShared(v) ) return false;
    return (parma::getOwner(m,v) == peer);
  }

  // vertex based BFS
  // return an array of vertex, edge and element weights
  // - no one needs faces... yet
  // the returned array needs to be deallocated
  double* runBFS(apf::Mesh* m, int layers, std::vector<apf::MeshEntity*> current,
      apf::MeshTag* visited, apf::MeshTag* wtag, int peer)
  {
    assert(layers>=0);
    const int elmDim = m->getDimension();
    double* weight = new double[4];
    for(unsigned int i=0; i<4; i++)
      weight[i] = 0;

    std::vector<apf::MeshEntity*> next;
    for (int i=1;i<=layers;i++) {
      for (unsigned int j=0;j<current.size();j++) {
        apf::MeshEntity* vertex = current[j];
        apf::Adjacent elms;
        apf::Downward verts;
        apf::Downward edges;
        m->getAdjacent(vertex, elmDim, elms);
        for(size_t k=0; k<elms.size(); k++) {
          if (!m->hasTag(elms[k],visited)) {
            //ghost elements
            m->setIntTag(elms[k],visited,&i);
            weight[elmDim] += parma::getEntWeight(m,elms[k],wtag);
            //ghost edges
            const int nedges = m->getDownward(elms[k],1,edges);
            for(int l=0; l < nedges; l++)
              if (!m->hasTag(edges[l],visited)) {
                m->setIntTag(edges[l],visited,&i);
                weight[1] += parma::getEntWeight(m,edges[l],wtag);
              }
            //ghost vertices
            const int nverts = m->getDownward(elms[k],0,verts);
            for(int l=0; l < nverts; l++)
              if (parma::isOwned(m, verts[l]) && !m->hasTag(verts[l],visited)) {
                next.push_back(verts[l]);
                m->setIntTag(verts[l],visited,&i);
                weight[0] += parma::getEntWeight(m,verts[l],wtag);
              }
          }
        }
      }
      current=next;
      next.clear();
    }
    PCU_Debug_Print("ghostW peer %d vtx %f edge %f elm %f\n",
        peer, weight[0], weight[1], weight[elmDim]);
    return weight;
  }

  double ownedWeight(apf::Mesh* m, apf::MeshTag* w, int dim) {
    apf::MeshIterator* it = m->begin(dim);
    apf::MeshEntity* e;
    double entW = 0;
    double sum = 0;
    while ((e = m->iterate(it))) {
      assert(m->hasTag(e,w));
      if (parma::isOwned(m,e)) {
        m->getDoubleTag(e,w,&entW);
        sum += entW;
      }
    }
    m->end(it);
    return sum;
  }
{'fraction_non_alphanumeric': 0.17267720731923966, 'fraction_numerical': 0.006928406466512702, 'mean_word_length': 2.473164713140037, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 51, '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': '801191', 'n_tokens_mistral': 2112, 'n_tokens_neox': 2094, 'n_words': 422}