default_tuner.h

00001 //********************************************************************************
00002 // Copyright 2007-2010 Intel Corporation All Rights Reserved.                   **
00003 //                                                                              **
00004 // The source code contained or described herein and all documents related to   **
00005 // the source code ("Material") are owned by Intel Corporation or its suppliers **
00006 // or licensors. Title to the Material remains with Intel Corporation or its    **
00007 // suppliers and licensors. The Material contains trade secrets and proprietary **
00008 // and confidential information of Intel or its suppliers and licensors. The    **
00009 // Material is protected by worldwide copyright and trade secret laws and       **
00010 // treaty provisions. No part of the Material may be used, copied, reproduced,  **
00011 // modified, published, uploaded, posted, transmitted, distributed, or          **
00012 // disclosed in any way without Intel's prior express written permission.       **
00013 //                                                                              **
00014 // No license under any patent, copyright, trade secret or other intellectual   **
00015 // property right is granted to or conferred upon you by disclosure or delivery **
00016 // of the Materials, either expressly, by implication, inducement, estoppel or  **
00017 // otherwise. Any license under such intellectual property rights must be       **
00018 // express and approved by Intel in writing.                                    **
00019 //********************************************************************************
00020 
00021 
00022 #ifndef CNC_DEFAULT_TUNER_H_ALREADY_INCLUDED
00023 #define CNC_DEFAULT_TUNER_H_ALREADY_INCLUDED
00024 
00025 #include <cnc/internal/cnc_api.h>
00026 #include <cnc/default_partitioner.h>
00027 #include <cnc/internal/step_delayer.h>
00028 
00029 namespace CnC {
00030 
00031     template< class T > class context;
00032     namespace Internal {
00033         template< class Tag, class Range, class StepColl, class RangeStepI, class TIR, bool deps > struct range_step;
00034     }
00035 
00036     enum {
00037         PASS_ON_LOCAL = -1,       ///< let tuner::pass_on return PASS_ON_NO if the step should be executed locally
00038         PASS_ON_ROUND_ROBIN = -2  ///< let tuner::pass_on return PASS_ON_ROUND_ROBIN to let the scheduler distribute it in a round-robin fashion
00039     };
00040 
00041     /// \brief Default (NOP) implementations of the tuner interface.
00042     ///
00043     /// Also defines the interface a user-provided tuner must satisfy.
00044     /// Derive your tuner from this class if you do not want to define the entire interface.
00045     ///
00046     /// \#include <cnc/default_tuner.h>
00047     template< typename Tag, typename Arg, bool check_deps = true, typename Partitioner = default_partitioner<> >
00048     struct /*CNC_API*/ default_tuner
00049     {
00050         /// \brief Allows defnintion of priorites to individual steps (which are identified by the tag).
00051         /// \return the default implementation always return 1.
00052         /// \param tag the tag which identifies the step to be executed
00053         /// \param arg the argument as passed to context< Derived >::prescribed (usually the context)
00054         int priority( const Tag & /*tag*/, Arg & /*arg*/ ) const
00055         {
00056             return 1;
00057         }
00058 
00059         /// \brief Allows declaration of data dependencies (to items) of
00060         /// given step (identified by the tag).
00061         ///
00062         /// When a step-instance is prescribed through a corresponding
00063         /// tag_collection::put, this method will be called.  You can
00064         /// declare dependencies to items by calling dC.depends(
00065         /// item_collection, dependent_item_tag ) for every item the step
00066         /// is going to 'get' in its execute mthod. The actual step
00067         /// execution will be delayed until all dependencies can be
00068         /// satisfied.  The default implementation does nothing (NOP). Your
00069         /// own implementation must accept dC by reference (T&).
00070         /// \param tag the tag which identifies the step to be executed.
00071         /// \param arg the argument as passed to context< Derived >::prescribed
00072         ///            (usually the context)
00073         /// \param dC  opaque object (must be by reference!) providing method depends
00074         ///            to declare item dependencies
00075         template< typename T >
00076         void depends( const Tag & /*tag*/, Arg & /*arg*/, T & /*dC*/ ) const
00077         {
00078         }
00079 
00080         /// \brief returns whether the step should be pre-scheduled 
00081         ///
00082         /// Pre-scheduling provides an alternative method for detecting
00083         /// data dependencies.
00084         ///
00085         /// The step instance will be run immediately when prescribed
00086         /// by a tag_collection::put. All items that are not yet available
00087         /// when accessed by the non-blocking get method will automatically
00088         /// be treated as dependent items. The pre-run will end at
00089         /// context::flush_gets() if any items are unavailable.  The step
00090         /// execution will be delayed until all detected dependencies can
00091         /// be satisfied.
00092         bool preschedule() const
00093         {
00094             return false;
00095         }
00096         /// \brief tell the scheduler on which process to run the step (distCnC)
00097         /// \return process id where the step will be executed, or PASS_ON_ROUND_ROBIN, or PASS_ON_LOCAL
00098         int pass_on( const Tag & /*tag*/, Arg & /*arg*/ ) const
00099         {
00100             return PASS_ON_ROUND_ROBIN;
00101         }
00102 
00103         /// \brief The type of the partitioner
00104         typedef Partitioner partitioner_type;
00105 
00106         /// \brief return a partitioner for range-based features, such as parallel_for
00107         /// \see default_partitioner for the expected signature of partitioners
00108         /// overwrite partitioner() if it doesn't come with default-constructor or
00109         /// if the default constructor is insufficient.
00110         partitioner_type partitioner() const
00111         {
00112             return partitioner_type();
00113         }
00114 
00115         /// true if steps launched through ranges consume items or need global locking, false otherwise.
00116         /// Avoiding checks for dependencies and global locks saves overhead and will perform better (e.g. for parallel_for).
00117         /// Safe execution (with checks) is the default (check_deps template argument).
00118         static const bool check_deps_in_ranges = check_deps;
00119     };
00120 
00121 
00122 } // end namespace CnC
00123 
00124 
00125 #endif //CNC_DEFAULT_TUNER_H_ALREADY_INCLUDED

Generated on Tue Aug 31 15:30:27 2010 for CnC by  doxygen 1.5.6