Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

tree_skeletons.h

Go to the documentation of this file.
00001 /***
00002  * Copyright (c) 2005, SkeTo Project
00003  * All rights reserved.
00004  */
00012 #ifndef __TREE_SKELETONS_H__
00013 #define __TREE_SKELETONS_H__
00014 
00015 #include "node.h"
00016 #include "dist_tree.h"
00017 #include "../util/compose.h"
00018 
00022 class tree_skeletons
00023 {
00025   // Data parallel Skeletons
00026 
00062 public:
00063   template< typename K1, typename K2 >
00064   static dist_tree< typename K1::result_type > *
00065   map( const K1 &k1,
00066        const K2 &k2,
00067        dist_tree< typename K1::argument_type > *t );
00068 
00069 private:
00070   template< typename C, typename A, typename K1, typename K2 >
00071   static dist_tree< C > *map_adapter( const K1 &k1,
00072                       const K2 &k2,
00073                       dist_tree< A > *t );
00074 
00075 private:
00076   template< typename C, typename A, typename K1, typename K2 >
00077   static node< C >* map_rec( const K1 &k1,
00078                  const K2 &k2,
00079                  node< A > *root );
00080 
00119 public:
00120   template< typename K1, typename K2 >
00121   static dist_tree< typename K1::result_type > *
00122   zipwith( const K1 &k1, 
00123        const K2 &k2,
00124        const dist_tree< typename K1::first_argument_type >* at, 
00125        const dist_tree< typename K1::second_argument_type >* bt );
00126 
00127 private:
00128   template< typename E, typename A, typename C, typename K1, typename K2 >
00129   static dist_tree< E >* zipwith_adapter( const K1 &k1, 
00130                       const K2 &k2,
00131                       const dist_tree< A >* at, 
00132                       const dist_tree< C >* bt );
00133 
00134 private:
00135   template< typename E, typename A, typename C, typename K1, typename K2 >
00136   static node< E >* zipwith_rec( const K1 &k1, 
00137                  const K2 &k2, 
00138                  const node< A >* root_a,
00139                  const node< C >* root_b );
00140 
00209 public:
00210   template< typename K1, typename K2,
00211         typename PSI, typename PHIL, typename PHIR, typename GG >
00212   static typename K1::result_type
00213   reduce( const K1 &k1, 
00214       const K2 &k2, 
00215       const PSI &psi,
00216       const PHIL &phiL,
00217       const PHIR &phiR,
00218       const GG &G,
00219       const dist_tree< typename K1::argument_type >* t );
00220 
00221 private:
00222   template< typename C, typename D, typename A, typename K1, typename K2,
00223         typename PSI, typename PHIL, typename PHIR, typename GG >
00224   static C reduce_adapter( const K1 &k1, 
00225                const K2 &k2, 
00226                const PSI &psi,
00227                const PHIL &phiL,
00228                const PHIR &phiR,
00229                const GG &G,
00230                const dist_tree< A >* t );
00231 
00238 private:
00239   template< typename C, typename D >
00240   struct reduce_result_t {
00241     enum {
00242       TYPEC,
00243       TYPED,
00244     } resulttype;
00245     C valC;
00246     D valD;
00247   };
00248 
00249 private:
00250   template< typename C, typename D, typename A, typename K1, typename K2,
00251         typename PSI, typename PHIL, typename PHIR >
00252   static tree_skeletons::reduce_result_t< C, D >
00253   reduce_local_rec( const K1 &k1,
00254             const K2 &k2,
00255             const PSI &psi,
00256             const PHIL &phiL,
00257             const PHIR &phiR, 
00258             const node< A >* root );
00259 
00260 private:
00261   template< typename C, typename D, typename A, typename GG >
00262   static C reduce_global( const GG &G,
00263               const tree_skeletons::reduce_result_t< C, D > &local_result,
00264               const dist_tree< A > *t );
00265   
00327 public:
00328   template< typename K1, typename K2,
00329         typename PSI, typename PHIL, typename PHIR, typename GG >
00330   static dist_tree< typename K1::result_type > *
00331   uAcc( const K1 &k1,
00332     const K2 &k2,
00333     const PSI &psi,
00334     const PHIL &phiL,
00335     const PHIR &phiR,
00336     const GG &G,
00337     const dist_tree< typename K1::argument_type > *t );
00338 
00339 private:
00340   template< typename C, typename D, typename A, typename K1, typename K2,
00341         typename PSI, typename PHIL, typename PHIR, typename GG >
00342   static dist_tree< C >* uAcc_adapter( const K1 &k1,
00343                        const K2 &k2,
00344                        const PSI &psi,
00345                        const PHIL &phiL,
00346                        const PHIR &phiR,
00347                        const GG &G,
00348                        const dist_tree< A > *t );
00349 
00350 private:
00351   template< typename C, typename D, typename A, typename GG >
00352   static void uAcc_global_uAcc( const GG &G, 
00353                 const tree_skeletons::reduce_result_t< C, D > &local_result,
00354                 C *vall,
00355                 C *valr,
00356                 const dist_tree< A > *t );
00357 
00358 private:
00359   template< typename C, typename D, typename A, typename K1, typename K2 >
00360   static node< C >* uAcc_local_uAcc_rec( const K1 &k1,
00361                      const K2 &k2, 
00362                      const C& left_result,
00363                      const C& right_result,
00364                      const node< A > *root );
00365 
00416 public:
00417   template< typename OPLUS, typename GL, typename GR >
00418   static dist_tree< typename OPLUS::result_type > *
00419   dAcc( const OPLUS &oplus,
00420     const typename OPLUS::result_type &e_oplus,
00421     const GL &gl,
00422     const GR &gr,
00423     const typename OPLUS::result_type &c,
00424     const dist_tree< typename GL::argument_type >* t );
00425 
00426 private:
00427   template< typename C, typename A, typename OPLUS, typename GL, typename GR >
00428   static dist_tree< C >* dAcc_adapter( const OPLUS &oplus,
00429                        const C &e_oplus,
00430                        const GL &gl,
00431                        const GR &gr,
00432                        const C &c,
00433                        const dist_tree< A >* t );
00434 
00435 private:
00436   template< typename C, typename A, typename OPLUS, typename GL, typename GR >
00437   static bool dAcc_local_path_rec( const OPLUS &oplus,
00438                    const GL &gl,
00439                    const GR &gr,
00440                    const node< A >* root,
00441                    C *c_to_left,
00442                    C *c_to_right );
00443 
00444 private:
00445   template< typename C, typename A, typename OPLUS >
00446   static C dAcc_global_dAcc( const OPLUS &oplus,
00447                  const C &c,
00448                  const C &c_to_left,
00449                  const C &c_to_right,
00450                  const dist_tree< A >* t );
00451 
00452 private:
00453   template< typename C, typename A, typename OPLUS, typename GL, typename GR >
00454   static node< C >* dAcc_local_dAcc_rec( const OPLUS &oplus,
00455                      const GL &gl,
00456                      const GR &gr, 
00457                      const C &c,
00458                      const node< A >* root );
00459 
00461   // Communication Skeletons
00462 
00473 public:
00474   template< typename A >
00475   static dist_tree< A >* distribute( const node< A >* tree );
00476 
00487 public:
00488   template< typename A >
00489   static dist_tree< A >* distribute2( const node< A >* tree );
00490 
00491 private:
00492   template< typename A >
00493   struct size_and_critical {
00494     int left_size;
00495     int right_size;
00496     const node< A >* critical_node;
00497   };
00498 
00499 private:
00500   template< typename A >
00501   static bool compute_size_and_get_global_tree( const node< A >* tree,
00502                         int nprocs,
00503                         node< size_and_critical< A > >** global_root,
00504                         int *np,
00505                         int *size );
00506 
00507 private:
00508   template< typename A >
00509   static void get_global_tree_rec( node< size_and_critical< A > >** global_tree,
00510                    int *size_root,
00511                    const node< A >* tree,
00512                    int m );
00513   
00514 private:
00515   template< typename A >
00516   static void serialize_global_structure( const node< A >* tree,
00517                       const node< size_and_critical< A > >* global_root,
00518                       int size, 
00519                       int *flags,
00520                       int *localsizes,
00521                       const node< A >** subroots,
00522                       const node< A >** subcrits );
00523 
00524 private:
00525   template< typename A >
00526   static void serialize_global_structure_rec( const node< A >* tree,
00527                           const node< size_and_critical< A > >* global_root,
00528                           int size,
00529                           int *flags,
00530                           int *localsizes,
00531                           const node< A >** subroots,
00532                           const node< A >** subcrits,
00533                           int *index );
00534                           
00535 private:
00536   template< typename A >
00537   static void get_local_tree( const node< A >* root,
00538                   const node< A >* crit_node,
00539                   int *flags,
00540                   A *values );
00541 
00542 private:
00543   template< typename A >
00544   static void get_local_tree_rec( const node< A >* root,
00545                   const node< A >* crit_node,
00546                   int *flags,
00547                   A *values,
00548                   int *index );
00549 
00557 public:
00558   template< typename A >
00559   static node< A >* gather( const dist_tree< A >* tree );
00560   
00561 private:
00562   template< typename A >
00563   static void gather_rec( node< A >* root,
00564               const node< int >* global_root,
00565               int *proc );
00566 
00567 private:
00568   template< typename A >
00569   static node< A >* gather_find_cutnode( node< A >* root );
00570 
00571 private:
00572   template< typename A >
00573   static node< A >* gather_create_subtree( const int* flags,
00574                        const A* values );
00575   
00576 private:
00577   template< typename A >
00578   static node< A >* gather_copy_tree( const node< A >* root );
00579 
00599 public:
00600   template< typename A >
00601   static dist_tree< A >* shiftp( const A& rootval,
00602                  const dist_tree< A >* tree );
00603 
00604 private:
00605   template< typename A >
00606   static node< A > *shiftp_rec( const node< A >* root,
00607                 const A& root_val, 
00608                 A *cut_node_val );
00609 
00632 public:
00633   template< typename A >
00634   static dist_tree< A >* shiftl( const A& leafval,
00635                  const dist_tree< A >* tree );
00636 
00637 private:
00638   template< typename A >
00639   static node< A >* shiftl_rec( const node< A > *root,
00640                 const A& leafval,
00641                 const A& left_child_root_val );
00642   
00665 public:
00666   template< typename A >
00667   static dist_tree< A >* shiftr( const A& leafval,
00668                  const dist_tree< A >* tree );
00669 
00670 private:
00671   template< typename A >
00672   static node< A >* shiftr_rec( const node< A > *root,
00673                 const A& leafval,
00674                 const A& right_child_root_val );
00675 
00676 };
00677 
00678 #include "tree_skeletons.tpp"
00679 
00680 #endif /* __TREE_SKELETONS_H__ */
00681 

Generated on Wed Jan 18 22:19:29 2006 for SkeTo -- Skeleton Library in Tokyo by  doxygen 1.4.4