00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef COMPONENTS_TRIG_CPU_TEST_MPI_H
00014 #define COMPONENTS_TRIG_CPU_TEST_MPI_H
00015
00016 #include "algorithm.h"
00017 #include "trig_cpu.h"
00018
00019 #define TEST_MPI_BUF_SIZE 32
00020
00021 class test_mpi : public algorithm {
00022 public:
00023 test_mpi(trig_cpu *cpu) : algorithm(cpu)
00024 {
00025 ptl = cpu->getPortalsHandle();
00026 }
00027
00028 bool
00029 operator()(Event *ev)
00030 {
00031 int handle;
00032
00033 switch (state) {
00034 case 0:
00035 printf("%5d: Inializing...\n",my_id);
00036 recv_buffer = new uint64_t[TEST_MPI_BUF_SIZE];
00037 send_buffer = new uint64_t[TEST_MPI_BUF_SIZE];
00038
00039 {
00040 int temp = my_id;
00041 for ( int i = 0; i < TEST_MPI_BUF_SIZE; i++ ) {
00042 recv_buffer[i] = temp;
00043 send_buffer[i] = temp++;
00044 }
00045 }
00046
00047 state = 1;
00048 break;
00049
00050 case 1:
00051 cpu->isend((my_id + 1) % num_nodes,send_buffer,TEST_MPI_BUF_SIZE*8/4);
00052 start_time = cpu->getCurrentSimTimeNano();
00053 state = 2;
00054 break;
00055
00056 case 2:
00057 cpu->irecv((my_id + num_nodes - 1) % num_nodes,recv_buffer,handle);
00058 state = 3;
00059 break;
00060
00061 case 3:
00062 cpu->irecv((my_id + num_nodes - 1) % num_nodes,&recv_buffer[TEST_MPI_BUF_SIZE/2],handle);
00063 start_time = cpu->getCurrentSimTimeNano();
00064 state = 4;
00065 break;
00066
00067 case 4:
00068 cpu->isend((my_id + 1) % num_nodes,send_buffer,TEST_MPI_BUF_SIZE*8/4);
00069 state = 5;
00070 break;
00071
00072 case 5:
00073 if ( cpu->waitall() )
00074 state = 6;
00075 break;
00076
00077 case 6:
00078 {
00079 for ( int i = 0; i < 32; i++ ) {
00080 printf("%5d: end -> send_buffer[%d] = %llu recv_buffer[%d] = %llu\n",my_id,i,send_buffer[i],i,recv_buffer[i]);
00081 }
00082 uint64_t elapsed_time = cpu->getCurrentSimTimeNano()-start_time;
00083 trig_cpu::addTimeToStats(elapsed_time);
00084 return true;
00085 state = 7;
00086 }
00087 break;
00088
00089 case 7:
00090 state = 7;
00091 break;
00092
00093 case 8:
00094 return false;
00095 break;
00096 default:
00097 break;
00098 }
00099 return false;
00100 }
00101
00102 private:
00103 test_mpi();
00104 test_mpi(const algorithm& a);
00105 void operator=(test_mpi const&);
00106
00107 trig_cpu *cpu;
00108 portals *ptl;
00109 ptl_handle_ct_t ct_handle;
00110 int state;
00111 int my_id;
00112 int num_nodes;
00113
00114 ptl_handle_md_t md_handle;
00115
00116 uint64_t* send_buffer;
00117 uint64_t* recv_buffer;
00118
00119 SimTime_t start_time;
00120
00121 };
00122
00123 #endif // COMPONENTS_TRIG_CPU_TEST_MPI_H