doc: Add serial to list of ci file reserved words
[charm.git] / src / ck-perf / trace-projectionsBOC.h
index 2b337a5d0df0c3917adbf4e2ee3e09b38315134b..fd63e0b80a20589608d3cd91fccf84393afec0f5 100644 (file)
+#include "envelope.h"
+#include "register.h"
+#include "trace-common.h"
+#include "ckcallback-ccs.h"
 
+#include <set>
+
+#ifndef PROJ_ANALYSIS
+// NOTE: Needed to handle the automatically-generated method so 
+//   trace-projections would build correctly while ignoring any of the 
+//   BOC-based definitions generated by parsing trace-projections.ci.
+//   Hence, we do not include TraceProjections.decl.h in this version.
+//
+//   This version of trace-projections would not permit any form of
+//   end-of-run operations and NONE of the definitions found in 
+//   trace-projections.ci would be visible to the rest of the code
+//   (trace-projections.C), so some care would be needed to ensure 
+//   PROJ_ANALYSIS encloses the correct code-fragments in 
+//   trace-projections.C
+void _registerTraceProjections() {
+  // faked call that does nothing.
+}
+#else
 #include "TraceProjections.decl.h"
 
-extern CkGroupID traceProjectionsGID;
+class KMeansStatsMessage : public CMessage_KMeansStatsMessage {
+ public:
+  int numMetrics;
+  int numKPos;
+  int numStats;
+  bool *filter;
+  double *kSeedsPos;
+  double *stats;
+};
 
-class TraceProjectionsInit : public Chare {
-  public:
-  TraceProjectionsInit(CkArgMsg*) {
-    traceProjectionsGID = CProxy_TraceProjectionsBOC::ckNew();
-  }
-  TraceProjectionsInit(CkMigrateMessage *m):Chare(m) {}
+class KSeedsMessage : public CMessage_KSeedsMessage {
+ public:
+  int numKPos;
+  double *kSeedsPos;
 };
 
-class OutlierStatsMessage : public CMessage_OutlierStatsMessage {
+class TraceProjectionsInit : public Chare {
  public:
-  double *stats;
+  TraceProjectionsInit(CkArgMsg *msg);
+ TraceProjectionsInit(CkMigrateMessage *m):Chare(m) {}
 };
 
-class OutlierWeightMessage : public CMessage_OutlierWeightMessage {
+class KSelectionMessage : public CMessage_KSelectionMessage {
  public:
-  int sourcePe;
-  double weight;
+  int numKMinIDs;
+  int numKMaxIDs;
+  int *minIDs;
+  int *maxIDs;
 };
 
-class OutlierThresholdMessage : public CMessage_OutlierThresholdMessage {
+class KMeansBOC : public CBase_KMeansBOC {
+ private:
+  // commandline parameters
+  bool autoCompute;
+  int numK;
+  int peNumKeep;
+  double entryThreshold;
+  bool usePhases;
+
+  int numKReported;
+
+  // variables for correct data gathering across phases
+  bool markedBegin;
+  bool markedIdle;
+  double beginBlockTime;
+  double beginIdleBlockTime;
+  int lastBeginEPIdx;
+  int numSelectionIter;
+  bool selected;
+
+  int currentPhase;
+  int lastPhaseIdx;
+  double *currentExecTimes;
+
+  // kMeans outlier structures - ALL processors will host this data
+  int numEntryMethods;
+  int numMetrics;
+  int phaseIter;
+
+  bool *keepMetric;
+  double *incKSeeds;
+  double minDistance; // distance to the closest seed
+  int lastMinK;
+  int minK; // the seed closest to the processor
+
+  // ONLY processor 0 will host this data, the location vector of K seeds
+  // This is actually a 2-D array, we need it to be contiguous for
+  //   communication purposes.
+  double *kSeeds; 
+  int *kNumMembers;
+
+  int *exemplarChoicesLeft;
+  int *outlierChoicesLeft;
+
  public:
-  double threshold;
+ KMeansBOC(bool outlierAutomatic, int numKSeeds, int _peNumKeep,
+          double _entryThreshold, bool outlierUsePhases) :
+  autoCompute(outlierAutomatic), numK(numKSeeds), 
+    peNumKeep(_peNumKeep), entryThreshold(_entryThreshold),
+    usePhases(outlierUsePhases) {};
+ KMeansBOC(CkMigrateMessage *m):CBase_KMeansBOC(m) {};
+  
+  void startKMeansAnalysis();
+  void flushCheck(CkReductionMsg *msg);
+  void flushCheckDone();
+  void getNextPhaseMetrics();
+  void collectKMeansData(); // C++ method
+  void globalMetricRefinement(CkReductionMsg *msg);
+  void initKSeeds(); // C++ method
+  void findInitialClusters(KMeansStatsMessage *msg);
+  void updateKSeeds(CkReductionMsg *msg);
+  double calculateDistance(int k); // C++ method
+  void updateSeedMembership(KSeedsMessage *msg);
+  void findRepresentatives(); // C++ method
+  void collectDistances(KSelectionMessage *msg);
+  void findNextMinMax(CkReductionMsg *msg);
+  void phaseDone();
+
+  /*
+  void calculateWeights(KMeansStatsMessage *);
+  void determineOutliers(OutlierWeightMessage *);
+  void setOutliers(OutlierThresholdMessage *);
+  */
 };
 
 class TraceProjectionsBOC : public CBase_TraceProjectionsBOC {
-private:
+ private:
+  bool findOutliers;
+  bool findStartTime;
+
+  int parModulesRemaining;
+
   double dummy;
   double endTime;
   double analysisStartTime;
-  double *execTimes;
-  double weight;
-  int encounteredWeights;
-  double *weightArray;
-  int *mapArray;
+  int endPe;                          // end PE which calls CkExit()
+  std::set<int> list;
+  int          flush_count;
+ public:
+ TraceProjectionsBOC(bool _findOutliers, bool _findStartTime) : findOutliers(_findOutliers), findStartTime(_findStartTime), parModulesRemaining(0), endPe(-1), flush_count(0) {};
+ TraceProjectionsBOC(CkMigrateMessage *m):CBase_TraceProjectionsBOC(m), parModulesRemaining(0), endPe(-1), flush_count(0) {};
 
-  FILE *outlierfp;
-  
-public:
-  TraceProjectionsBOC(void) {};
-  TraceProjectionsBOC(CkMigrateMessage *m):CBase_TraceProjectionsBOC(m) {};
-  void startOutlierAnalysis();
-  void outlierAverageReduction(CkReductionMsg *);
-  void calculateWeights(OutlierStatsMessage *);
-  void determineOutliers(OutlierWeightMessage *);
-  void setOutliers(OutlierThresholdMessage *);
+  void traceProjectionsParallelShutdown(int);
+  void startTimeAnalysis();
+  void startTimeDone(CkReductionMsg *);
   void startEndTimeAnalysis();
-  void endTimeReduction(CkReductionMsg *);
-  void finalReduction(CkReductionMsg *);
+  void endTimeDone(CkReductionMsg *);
+  void kMeansDone(CkReductionMsg *);
+  void kMeansDone(void);
+  void finalize(void);
   void shutdownAnalysis(void);
-  void closeTrace(void);
-};
+  void closingTraces(void);
+  void closeParallelShutdown(CkReductionMsg *);
 
+  void ccsOutlierRequest(CkCcsRequestMsg *);
 
+  void flush_warning(int pe);
+  void print_warning();
+};
+#endif