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 "algorithm.h"
00017 #include <string.h>
00018
00019 class bcast_tree : public algorithm {
00020 public:
00021 bcast_tree(trig_cpu *cpu) : algorithm(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 int bad = 0;
00042
00043 crBegin();
00044
00045 start_time = cpu->getCurrentSimTimeNano();
00046 cpu->addBusyTime("200ns");
00047 crReturn();
00048
00049 if (my_root == my_id) memcpy(out_buf, in_buf, msg_size);
00050
00051 for (i = 0 ; i < msg_size ; i += chunk_size) {
00052 comm_size = (msg_size - i > chunk_size) ? chunk_size : msg_size - i;
00053 if (my_root != my_id) {
00054 while (!cpu->irecv(my_root, out_buf + i, handle)) { crReturn(); }
00055 crReturn();
00056 }
00057 while (!cpu->waitall()) { crReturn(); }
00058 crReturn();
00059 for (j = 0 ; j < num_children ; ++j) {
00060 cpu->isend(my_children[j], in_buf + i, comm_size);
00061 crReturn();
00062 }
00063 }
00064 crReturn();
00065 trig_cpu::addTimeToStats(cpu->getCurrentSimTimeNano()-start_time);
00066
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 crFinish();
00073 return true;
00074 }
00075
00076 private:
00077 bcast_tree();
00078 bcast_tree(const algorithm& a);
00079 void operator=(bcast_tree const&);
00080
00081 SimTime_t start_time;
00082 int radix;
00083 int i, j;
00084 int handle;
00085
00086 int msg_size;
00087 int chunk_size;
00088 int comm_size;
00089
00090 char *in_buf;
00091 char *out_buf;
00092
00093 int my_root;
00094 std::vector<int> my_children;
00095 int num_children;
00096 };
00097
00098 #endif // COMPONENTS_TRIG_CPU_BCAST_TREE_H