tapioca.hpp 4.03 KB
Newer Older
1 2
#ifndef TAPIOCA_H
#define TAPIOCA_H
Francois Tessier's avatar
Francois Tessier committed
3 4 5 6 7 8 9 10

#define MASTER 0

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <float.h>
11
#include <string.h>
Francois Tessier's avatar
Francois Tessier committed
12 13 14 15 16 17
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include "mpi.h"

18
#include "tp_topology.hpp"
19
#include "tp_memory.hpp"
Francois Tessier's avatar
Francois Tessier committed
20 21 22 23 24 25

enum MAPPING_STRATEGY
  {
    SHORTEST_PATH,
    LONGEST_PATH,
    TOPOLOGY_AWARE,
26
    MEMORY_AWARE,
Francois Tessier's avatar
Francois Tessier committed
27
    CONTENTION_AWARE,
28 29
    UNIFORM,
    RANDOM
Francois Tessier's avatar
Francois Tessier committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
  };

enum MEMORY_LAYOUT
  {
    ARRAY_OF_STRUCTURES,
    STRUCTURE_OF_ARRAYS
  };

typedef struct Round Round_t;
struct Round
{
  int aggr;
  int round;
};

  
Francois Tessier's avatar
Francois Tessier committed
46
class Tapioca
Francois Tessier's avatar
Francois Tessier committed
47 48
{
 public:
Francois Tessier's avatar
Francois Tessier committed
49 50
  Tapioca ();
  ~Tapioca ();
Francois Tessier's avatar
Francois Tessier committed
51
  
52
  void Init (int64_t *chunkCount, int *chunkSize, int64_t *chunkOffset,
53
	     int nChunks, int64_t header, char* fileName, MPI_Comm comm);
54 55

  int Write ( MPI_Offset offset, void *buf, int count, MPI_Datatype datatype,
56
	     MPI_Status *status, int64_t bufOffset = 0);
57

58
  int Read  ( MPI_Offset offset, void *buf, int count, MPI_Datatype datatype,
59 60
	      MPI_Status *status, int64_t bufOffset = 0);

Francois Tessier's avatar
Francois Tessier committed
61 62 63 64
  void Finalize ();

  void MPIIOInfo (MPI_File fileHandle);

65 66 67 68 69
  /***********************/
  /*      TOPOLOGY       */
  /***********************/
  Topology topology;

70
protected:
Francois Tessier's avatar
Francois Tessier committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84
  /***********************/
  /*  INITIALIZATION     */
  /***********************/
  void SetDefaultValues ();
  void ParseEnvVariables ();
  void SetCommValues ();
  void SetOffsets ();
  void SetNodesList ();

  /***********************/
  /*    AGGREGATION      */
  /***********************/
  int NumberOfAggregators ();
  void IdentifyMyAggregators ();
85 86 87
  void setAggregationTier ( );
  void setTargetTier ( char* fileName );
  void SelectOneAggregatorPerNode ();
88
  void KeepAggregators ();
Francois Tessier's avatar
Francois Tessier committed
89 90
  void ElectAggregators ();
  int64_t DataSizeSentToAggr (int aggrId);
91 92
  void Push ();
  void Pull ();
93
  void GlobalFence ();
Francois Tessier's avatar
Francois Tessier committed
94 95 96 97 98 99 100

  /***********************/
  /*     PLACEMENT       */
  /***********************/
  int RankShortestPath (MPI_Comm aggrComm, int64_t dataSize);
  int RankLongestPath (MPI_Comm aggrComm, int64_t dataSize);
  int RankTopologyAware (MPI_Comm aggrComm, int64_t dataSize);
101
  int RankMemoryAware (MPI_Comm aggrComm, int64_t dataSize);
Francois Tessier's avatar
Francois Tessier committed
102 103
  int RankContentionAware (MPI_Comm aggrComm, int64_t dataSize);
  int RankUniformDistribution (MPI_Comm aggrComm, int64_t dataSize);
104
  int RankRandom (MPI_Comm aggrComm, int64_t dataSize);
Francois Tessier's avatar
Francois Tessier committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
  int CoordsToInt (int *coords, int dim);
  
  /***********************/
  /*  OFFSET MANAGEMENT  */
  /***********************/
  int64_t FileToBufferOffset ();
  int64_t BufferToFileOffset ();

  /***********************/
  /*        MISC.        */
  /***********************/
  const char* getStrategyName ();
  void HandleMPIError (int retval);
  void PrintTime (double startTime, double endTime, char* func);

  /***********************/
  /*      VARIABLES      */
  /***********************/
  int worldRank_;
  int commRank_;
  int commSize_;

  int64_t rankDataSize_;
  int64_t commDataSize_;

  int64_t *chunkCount_;
  int *chunkSize_;
  int64_t *chunkOffset_;
  int nChunks_;
  int nCommit_;

  int currentRound_;
137
  int totalRounds_;
138 139
  int readRound_;
  bool firstRead_;
140
  int totalNeededBuffers_;
Francois Tessier's avatar
Francois Tessier committed
141 142
  int64_t currentDataSize_;

143
  int hostId_;
144
  int nNodes_;
Francois Tessier's avatar
Francois Tessier committed
145 146 147 148 149 150 151 152 153 154 155 156
  std::map<int, bool> excludedNode;

  MPI_Comm subComm_;
  int64_t offsetInFile_;
  int64_t offsetInAggrData_;

  std::vector<int> globalAggregatorsRanks;
  std::vector<int> aggregatorsRanks;
  std::vector<int> roundsIds;
  std::vector<int> dataSize;
  std::vector< std::vector<int> > chunksIndexMatching;

157
  
158
  std::vector<Memory> memBuffers;
159
  Memory memTarget;
Francois Tessier's avatar
Francois Tessier committed
160 161
  
  /* AGGREGATOR */
162 163 164 165
  int nAggr_;
  int nBuffers_;  
  int64_t bufferSize_;
  mem_t memAggr_;
166 167
  bool reElectAggr_;
  bool electedAggr_;
168

Francois Tessier's avatar
Francois Tessier committed
169 170 171 172 173 174 175 176 177 178
  bool amAnAggr_;
  int globalAggrRank_;
  bool commSplit_;
  MAPPING_STRATEGY strategy_;
  int64_t aggrDataSize_;
  
  int totalWrites_;
  int writeCounter_;

  bool writeDevNull_;
179
  
180
  bool pipelinedBuffers_;
Francois Tessier's avatar
Francois Tessier committed
181 182 183 184 185
  /* TIMING */
  double startAggrTime, endAggrTime, totAggrTime;
  double startIOTime, endIOTime, totIOTime;
};

186
#endif /* TAPIOCA_H */