<commit_before>/*
 * Communicator.hpp
 */

#ifndef COMMUNICATOR_HPP_
#define COMMUNICATOR_HPP_

#include "../include/pv_arch.h"
#include "../include/pv_types.h"
#include <stdlib.h>

#ifdef PV_USE_MPI
#  include <mpi.h>
#else
#  include "../include/mpi_stubs.h"
#endif // PV_USE_MPI

// number in communicating neighborhood
#define NUM_NEIGHBORHOOD 9

// directional indices
#define LOCAL     0
#define NORTHWEST 1
#define NORTH     2
#define NORTHEAST 3
#define WEST      4
#define EAST      5
#define SOUTHWEST 6
#define SOUTH     7
#define SOUTHEAST 8

namespace PV {

class Communicator {
public:

   static size_t recvOffset(int n, const PVLayerLoc * loc);
   static size_t sendOffset(int n, const PVLayerLoc * loc);

   static MPI_Datatype * newDatatypes(const PVLayerLoc * loc);

   Communicator(int * argc, char *** argv);
   virtual ~Communicator();

   int commInit(int * argc, char *** argv);
   int commFinalize();

   char * name()                { return commName; }

   int commRank()               { return icRank; }
   int commSize()               { return icSize; }
   MPI_Comm communicator()      { return icComm; }

   int numberOfNeighbors(); // includes interior (self) as a neighbor
   int numberOfBorders()        {return numBorders;}

   bool hasNeighbor(int neighborId);

   int commRow()          {return commRow(icRank);}
   int commColumn()       {return commColumn(icRank);}
   int numCommRows()      {return numRows;}
   int numCommColumns()   {return numCols;}

   int exchange(pvdata_t * data,
                const MPI_Datatype neighborDatatypes [],
                const PVLayerLoc * loc);

protected:

   int commRow(int commId);
   int commColumn(int commId);

   int numNeighbors;  // # of remote neighbors plus local
   int numBorders;    // # of border regions (no communicating neighbor)

   //TODO - can this be cleaned up?
   int borders[NUM_NEIGHBORHOOD-1];
   int neighbors[NUM_NEIGHBORHOOD];        // [0] is interior (local)
   int remoteNeighbors[NUM_NEIGHBORHOOD];

private:

   int mpi_initialized_on_entry;
   int icRank;
   int icSize;
   int worldRank;
   int worldSize;
   int numRows;
   int numCols;

   char commName[16];

   MPI_Comm    icComm;
   MPI_Request requests[NUM_NEIGHBORHOOD-1];

   // These methods are private for now, move to public as needed

   int neighborInit();<commit_msg>Declare mpi_initialized_on_entry only if PV_USE_MPI is set<commit_after>/*
 * Communicator.hpp
 */

#ifndef COMMUNICATOR_HPP_
#define COMMUNICATOR_HPP_

#include "../include/pv_arch.h"
#include "../include/pv_types.h"
#include <stdlib.h>

#ifdef PV_USE_MPI
#  include <mpi.h>
#else
#  include "../include/mpi_stubs.h"
#endif // PV_USE_MPI

// number in communicating neighborhood
#define NUM_NEIGHBORHOOD 9

// directional indices
#define LOCAL     0
#define NORTHWEST 1
#define NORTH     2
#define NORTHEAST 3
#define WEST      4
#define EAST      5
#define SOUTHWEST 6
#define SOUTH     7
#define SOUTHEAST 8

namespace PV {

class Communicator {
public:

   static size_t recvOffset(int n, const PVLayerLoc * loc);
   static size_t sendOffset(int n, const PVLayerLoc * loc);

   static MPI_Datatype * newDatatypes(const PVLayerLoc * loc);

   Communicator(int * argc, char *** argv);
   virtual ~Communicator();

   int commInit(int * argc, char *** argv);
   int commFinalize();

   char * name()                { return commName; }

   int commRank()               { return icRank; }
   int commSize()               { return icSize; }
   MPI_Comm communicator()      { return icComm; }

   int numberOfNeighbors(); // includes interior (self) as a neighbor
   int numberOfBorders()        {return numBorders;}

   bool hasNeighbor(int neighborId);

   int commRow()          {return commRow(icRank);}
   int commColumn()       {return commColumn(icRank);}
   int numCommRows()      {return numRows;}
   int numCommColumns()   {return numCols;}

   int exchange(pvdata_t * data,
                const MPI_Datatype neighborDatatypes [],
                const PVLayerLoc * loc);

protected:

   int commRow(int commId);
   int commColumn(int commId);

   int numNeighbors;  // # of remote neighbors plus local
   int numBorders;    // # of border regions (no communicating neighbor)

   //TODO - can this be cleaned up?
   int borders[NUM_NEIGHBORHOOD-1];
   int neighbors[NUM_NEIGHBORHOOD];        // [0] is interior (local)
   int remoteNeighbors[NUM_NEIGHBORHOOD];

private:

#ifdef PV_USE_MPI
   int mpi_initialized_on_entry;
#endif // PV_USE_MPI
   int icRank;
   int icSize;
   int worldRank;
   int worldSize;
   int numRows;
   int numCols;

   char commName[16];

   MPI_Comm    icComm;
   MPI_Request requests[NUM_NEIGHBORHOOD-1];

   // These methods are private for now, move to public as needed

   int neighborInit();
{'fraction_non_alphanumeric': 0.09744876620660811, 'fraction_numerical': 0.006273525721455458, 'mean_word_length': 2.9924874791318863, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7632211', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1552, 'n_words': 453}