00001 // Copyright 2009-2010 Sandia Corporation. Under the terms 00002 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. 00003 // Government retains certain rights in this software. 00004 // 00005 // Copyright (c) 2009-2010, Sandia Corporation 00006 // All rights reserved. 00007 // 00008 // This file is part of the SST software package. For license 00009 // information, see the LICENSE file in the top level directory of the 00010 // distribution. 00011 00012 #ifndef SST_INTROSPECTOR_H 00013 #define SST_INTROSPECTOR_H 00014 00015 00016 #include <sst/core/component.h> 00017 00018 00019 00020 namespace SST { 00021 00022 //TODO 00023 //#define _COMP_DBG( fmt, args...) __DBG( DBG_COMP, Component, fmt, ## args ) 00024 00025 #if DBG_INTROSPECTOR 00026 #define _INTROSPECTOR_DBG( fmt, args...)\ 00027 printf( "%d:Introspector::%s():%d: "fmt, _debug_rank, __FUNCTION__,__LINE__, ## args ) 00028 #else 00029 #define _INTROSPECTOR_DBG( fmt, args...) 00030 #endif 00031 00032 00033 00034 /** 00035 * Main introspector object for the simulation. 00036 * All models inherit from this. 00037 * Introspection interface is a unified way to gather statistics and arbitrary data from components. 00038 */ 00039 class Introspector: public Component { 00040 00041 public: 00042 typedef std::map<Component*, int> Database_t; 00043 00044 /** Types of boost MPI collective operations that introspector can perform.*/ 00045 enum collect_type { GATHER, ALLGATHER, BROADCAST, REDUCE, ALLREDUCE}; 00046 /** Types of funciton objects for the reduce collective.*/ 00047 enum mpi_operation { 00048 MINIMUM, 00049 MAXIMUM, 00050 SUM, 00051 NOT_APPLICABLE 00052 }; 00053 00054 00055 /** Constructor. Generally only called by the factory class. 00056 @param id Unique introspector ID*/ 00057 Introspector( ComponentId_t id ); 00058 virtual ~Introspector() = 0; 00059 00060 00061 00062 // main functions for introspection 00063 /** Get the map, compMap, that stores ID and pointers to the components on the rank from Simulation. 00064 This function is usually called in Introspector::getModels(). */ 00065 void getCompMap(); 00066 /** Get component of a certain type indicated by CompType on this rank. 00067 If CompType is blank, a list of all local components is returned. 00068 This function is usually used in Introspector::Setup(). 00069 @param CompType Component's type*/ 00070 std::list<Component*> getModels(const std::string CompType); 00071 /** Declare that this introspector will be monitoring a given component. 00072 The information of the introspector is also stored in the component's MyIntroList. 00073 This function is usually used in Introspector::Setup(). 00074 @param c Pointer to the component that will be monitored*/ 00075 void monitorComponent(Component* c); 00076 /** Store pointer to the component and the data ID of the integer data of interest in a local map. 00077 This function is usually used in Introspector::Setup(). 00078 @param c Pointer to the component that is monitored by this introspector 00079 @param dataID ID of the integer data */ 00080 void addToIntDatabase(Component* c, int dataID); 00081 /** Store pointer to the component and the data ID of the double data of interest in a local map. 00082 This function is usually used in Introspector::Setup(). 00083 @param c Pointer to the component that is monitored by this introspector 00084 @param dataID ID of the double data */ 00085 void addToDoubleDatabase(Component* c, int dataID); 00086 /** Query the components it is moniroting at regular intervals to retrieve components' statistics & data. 00087 Introspector-writers will implement their own pullData function. This function calls Component::getIntData() 00088 or Component::getDoubleData() to retrieve components' data, and is a good place to manipulate the data 00089 (print to screen, MPI collective communication, etc). 00090 This function can be invoked by an event handler triggered by a clock.*/ 00091 virtual bool pullData( Cycle_t ) { return false; } 00092 /** Introspectors communicate among themselves with Boost MPI to exchange their integer data, invalue. 00093 This function initiates a specific type of collective communicaiton indicated by ctype. The data 00094 are operated based on ctype and on the MPI operation, op. An introspector type can have periodic 00095 collective communication by calling this function in a member function registered with an event handler that is 00096 triggered by a clock. 00097 @param ctype Types of collective communication. Currently supported options are Broadcast, (all)gather, 00098 and (all)reduce 00099 @param invalue The local value to be communicated 00100 @param op Types of the MPI operations for the (all)reduce algorithm to combine the values. Currently 00101 supported options are summarize, minimum and maximum. Default is set to none 00102 @param rank The rank where the introspector resides. Default is set to 0. If ctype is broadcast, 00103 rank here indicates the rank that will transmitting the value*/ 00104 void collectInt(collect_type ctype, uint64_t invalue, mpi_operation op=NOT_APPLICABLE, int rank=0); 00105 /** One time introspectors collective communication. The event handling functors that calls a given member 00106 communication function is inserted into the queue and will be triggered at time specified by, time. 00107 The introspector-write implements their own communication function if they want something other than 00108 the basic collective operations, broadcast, (all)reduce and (all)gather. 00109 @param time The simulation time when the introspectors will communicate among themselves 00110 @param functor Event handling functor that invokes member communication function*/ 00111 void oneTimeCollect(SimTime_t time, EventHandlerBase<bool,Event*>* functor); 00112 00113 00114 /** List of components that this introspector is monitoring.*/ 00115 std::list<Component*> MyCompList; 00116 /** Database of the integer data monitored by this introspector available through Introspector::pullData().*/ 00117 Database_t DatabaseInt; 00118 /** Database of the double data monitored by this introspector available through Introspector::pullData().*/ 00119 Database_t DatabaseDouble; 00120 /** Minimum value of the integer values collected from all introspectors by Introspector::collectInt().*/ 00121 uint64_t minvalue; 00122 /** Maximum value of the integer values collected from all introspectors by Introspector::collectInt().*/ 00123 uint64_t maxvalue; 00124 /** Result value of the reduction operation in Introspector::collectInt().*/ 00125 uint64_t value; 00126 /** Data vector that holds data collected from all introspectors by Introspector::collectInt().*/ 00127 std::vector<uint64_t> arrayvalue; 00128 00129 00130 protected: 00131 Introspector(); 00132 00133 private: 00134 CompMap_t* simCompMap; 00135 }; 00136 00137 typedef std::map< ComponentId_t, Introspector* > IntroMap_t; 00138 00139 } //end namespace 00140 #endif