• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/elements/portals4_sm/trig_cpu/apps/bcast.h

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 
00013 #ifndef COMPONENTS_TRIG_CPU_BCAST_TREE_H
00014 #define COMPONENTS_TRIG_CPU_BCAST_TREE_H
00015 
00016 #include "sst/elements/portals4_sm/trig_cpu/application.h"
00017 #include <string.h>                    // for memcpy()
00018 
00019 class bcast_tree :  public application {
00020 public:
00021     bcast_tree(trig_cpu *cpu) : application(cpu)
00022     {
00023         radix = cpu->getRadix();
00024         msg_size = cpu->getMessageSize();
00025         chunk_size = cpu->getChunkSize();
00026 
00027         in_buf = (char*) malloc(msg_size);
00028         for (i = 0 ; i < msg_size ; ++i) {
00029             in_buf[i] = i % 255;
00030         }
00031         out_buf = (char*) malloc(msg_size);
00032 
00033         // compute my root and children
00034         boost::tie(my_root, my_children) = buildBinomialTree(radix);
00035         num_children = my_children.size();
00036     }
00037 
00038     bool
00039     operator()(Event *ev)
00040     {
00041         crBegin();
00042 
00043         start_time = cpu->getCurrentSimTimeNano();
00044         cpu->addBusyTime("200ns");
00045         crReturn();
00046 
00047         if (my_root == my_id) memcpy(out_buf, in_buf, msg_size);
00048 
00049         for (i = 0 ; i < msg_size ; i += chunk_size) {
00050             comm_size = (msg_size - i > chunk_size) ? chunk_size : msg_size - i;
00051             if (my_root != my_id) {
00052                 while (!cpu->irecv(my_root, out_buf + i, handle)) { crReturn(); }
00053                 crReturn();
00054             }
00055             while (!cpu->waitall()) { crReturn(); }
00056             crReturn();
00057             for (j = 0 ; j < num_children ; ++j) {
00058                 cpu->isend(my_children[j], in_buf + i, comm_size);
00059                 crReturn();
00060             }
00061         }
00062         crReturn();
00063         trig_cpu::addTimeToStats(cpu->getCurrentSimTimeNano()-start_time);
00064 
00065         {
00066             int bad = 0;
00067             for (i = 0 ; i < msg_size ; ++i) {
00068                 if ((out_buf[i] & 0xff) != i % 255) bad++;
00069             }
00070             if (bad) printf("%5d: bad results: %d\n",my_id,bad);
00071         }
00072 
00073         crFinish();
00074         return true;
00075     }
00076 
00077 private:
00078     bcast_tree();
00079     bcast_tree(const application& a);
00080     void operator=(bcast_tree const&);
00081 
00082     SimTime_t start_time;
00083     int radix;
00084     int i, j;
00085     int handle;
00086 
00087     int msg_size;
00088     int chunk_size;
00089     int comm_size;
00090 
00091     char *in_buf;
00092     char *out_buf;
00093 
00094     int my_root;
00095     std::vector<int> my_children;
00096     int num_children;
00097 };
00098 
00099 #endif // COMPONENTS_TRIG_CPU_BCAST_TREE_H

Generated on Fri Oct 22 2010 11:02:25 for SST by  doxygen 1.7.1