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

sst/elements/portals4_sm/trig_cpu/apps/ping_pong.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_PING_PONG_H
00014 #define COMPONENTS_TRIG_CPU_PING_PONG_H
00015 
00016 #include "sst/elements/portals4_sm/trig_cpu/application.h"
00017 #include "sst/elements/portals4_sm/trig_cpu/trig_cpu.h"
00018 
00019 #define PP_BUF_SIZE 1
00020 
00021 class ping_pong :  public application {
00022 public:
00023     ping_pong(trig_cpu *cpu) : application(cpu)
00024     {
00025         ptl = cpu->getPortalsHandle();
00026     }
00027 
00028     bool
00029     operator()(Event *ev)
00030     {
00031         ptl_md_t md;
00032         ptl_me_t me;
00033 
00034         ptl_handle_me_t me_handle;
00035 
00036         printf("state = %d\n",state);
00037         switch (state) {
00038         case 0:
00039             printf("%5d: Inializing...\n",my_id);
00040 
00041             ptl->PtlCTAlloc(PTL_CT_OPERATION,ct_handle);
00042             state = 1;
00043             break;
00044 
00045         case 1:
00046             recv_buffer = new uint64_t[PP_BUF_SIZE];
00047             send_buffer = new uint64_t[PP_BUF_SIZE];
00048 
00049             {
00050                 int temp = my_id;
00051                 for ( int i = 0; i < PP_BUF_SIZE; i++ ) {
00052                     recv_buffer[i] = temp;
00053                     send_buffer[i] = temp++;
00054                 }
00055             }
00056 
00057             md.start = send_buffer;
00058             md.length = 8*PP_BUF_SIZE;
00059             md.eq_handle = PTL_EQ_NONE;
00060             md.ct_handle = PTL_CT_NONE;
00061 //          md.ct_handle = ct_handle;
00062             ptl->PtlMDBind(md, &md_handle);
00063 
00064             state = 2;
00065             break;
00066             
00067         case 2:
00068             
00069             // initialize things
00070             me.start = recv_buffer;
00071             me.length = 8*PP_BUF_SIZE;
00072             me.ignore_bits = ~0x0;
00073             me.ct_handle = ct_handle;
00074             ptl->PtlMEAppend(0, me, PTL_PRIORITY_LIST, NULL, me_handle);
00075 
00076             for ( int i = 0; i < PP_BUF_SIZE; i++ ) {
00077                 printf("%5d: start -> send_buffer[%d] = %llu   recv_buffer[%d] = %llu\n",my_id,i,(long long unsigned)send_buffer[i],i,(long long unsigned)recv_buffer[i]);
00078             }
00079 
00080             
00081             state = 3;
00082             break;
00083 
00084         case 3:
00085           start_time = cpu->getCurrentSimTimeNano();
00086           ptl->PtlPut(md_handle,0,PP_BUF_SIZE*8,0,(my_id + 1) % num_nodes,0,0,0,NULL,0);  
00087           state = 4;
00088             break;
00089 
00090         case 4:
00091           if ( ptl->PtlCTWait(ct_handle,1) ) {
00092             state = 5;
00093           }
00094             break;
00095             
00096         case 5:
00097           ptl->PtlPut(md_handle,0,PP_BUF_SIZE*8,0,(my_id + (num_nodes - 1)) % num_nodes,0,0,0,NULL,0);  
00098           state = 6;
00099             break;
00100 
00101         case 6:
00102             if ( ptl->PtlCTWait(ct_handle,2) ) {
00103                 for ( int i = 0; i < PP_BUF_SIZE; i++ ) {
00104                     printf("%5d: end -> send_buffer[%d] = %llu   recv_buffer[%d] = %llu\n",my_id,i,(long long unsigned)send_buffer[i],i,(long long unsigned)recv_buffer[i]);
00105                 }
00106                 uint64_t elapsed_time = cpu->getCurrentSimTimeNano()-start_time;
00107                 trig_cpu::addTimeToStats(elapsed_time);
00108                 return true;
00109             }
00110             return false;
00111             break;
00112         default:
00113           break;
00114         }
00115         return false;
00116     }
00117 
00118 private:
00119     ping_pong();
00120     ping_pong(const application& a);
00121     void operator=(ping_pong const&);
00122 
00123     trig_cpu *cpu;
00124     portals *ptl;
00125     ptl_handle_ct_t ct_handle;
00126     int state;
00127     int my_id;
00128     int num_nodes;
00129     
00130     ptl_handle_md_t md_handle;
00131 
00132     uint64_t* send_buffer;
00133     uint64_t* recv_buffer;
00134 
00135     SimTime_t start_time;
00136     
00137 };
00138 
00139 #endif // COMPONENTS_TRIG_CPU_TEST_PORTALS_H

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