00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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>
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
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