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

#define MASTER 0
#define LATENCY 30
#define BANDWIDTH 1800000
#define NBUFFERS 2

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

21
#include "tp_network.hpp"
22
#include "tp_memory.hpp"
Francois Tessier's avatar
Francois Tessier committed
23 24 25 26 27 28 29

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

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
48
class Tapioca
Francois Tessier's avatar
Francois Tessier committed
49 50
{
 public:
Francois Tessier's avatar
Francois Tessier committed
51 52
  Tapioca ();
  ~Tapioca ();
Francois Tessier's avatar
Francois Tessier committed
53
  
54 55 56 57 58 59 60
  void Init (int64_t *chunkCount, int *chunkSize, int64_t *chunkOffset,
	     int nChunks, int64_t header, MPI_Comm comm);

  void setAggregationTier ( mem_t mem, char* fileName );
  void setTargetTier      ( mem_t mem, int64_t buffSize, char* fileName );

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

63
  int Read  ( MPI_Offset offset, void *buf, int count, MPI_Datatype datatype,
64 65
	      MPI_Status *status, int64_t bufOffset = 0);

Francois Tessier's avatar
Francois Tessier committed
66 67 68 69
  void Finalize ();

  void MPIIOInfo (MPI_File fileHandle);

70 71 72 73 74
  /***********************/
  /*      TOPOLOGY       */
  /***********************/
  Topology topology;

Francois Tessier's avatar
Francois Tessier committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
 private:
  /***********************/
  /*  INITIALIZATION     */
  /***********************/
  void SetDefaultValues ();
  void ParseEnvVariables ();
  void SetCommValues ();
  void SetOffsets ();
  void SetNodesList ();

  /***********************/
  /*    AGGREGATION      */
  /***********************/
  int NumberOfAggregators ();
  void IdentifyMyAggregators ();
  void ElectAggregators ();
  int64_t DataSizeSentToAggr (int aggrId);
92 93
  void Push ();
  void Pull ();
94
  void GlobalFence ();
Francois Tessier's avatar
Francois Tessier committed
95 96 97 98 99 100 101 102 103

  /***********************/
  /*     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);
  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 137
  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 nAggr_;
  int currentRound_;
138
  int totalRounds_;
139 140
  int readRound_;
  bool firstRead_;
141
  int totalNeededBuffers_;
Francois Tessier's avatar
Francois Tessier committed
142 143 144
  int64_t currentDataSize_;

  int intCoords_;
145
  int nNodes_;
Francois Tessier's avatar
Francois Tessier committed
146 147 148 149 150 151 152 153 154 155 156 157
  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;

158 159
  Memory memBuffer0;
  Memory memBuffer1;
160
  Memory memTarget;
Francois Tessier's avatar
Francois Tessier committed
161 162 163 164 165 166 167 168 169 170 171 172 173
  
  /* AGGREGATOR */
  bool amAnAggr_;
  int globalAggrRank_;
  bool commSplit_;
  MAPPING_STRATEGY strategy_;
  int64_t bufferSize_;
  int64_t aggrDataSize_;
  
  int totalWrites_;
  int writeCounter_;

  bool writeDevNull_;
174
  
175
  bool pipelinedBuffers_;
Francois Tessier's avatar
Francois Tessier committed
176 177 178 179 180
  /* TIMING */
  double startAggrTime, endAggrTime, totAggrTime;
  double startIOTime, endIOTime, totIOTime;
};

Francois Tessier's avatar
Francois Tessier committed
181
#endif /* TAPIOCA_H */