"Fossies" - the Fresh Open Source Software Archive

Member "NetPIPE-3.7.2/src/shmem.c" (19 Aug 2010, 2899 Bytes) of package /linux/privat/old/NetPIPE-3.7.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "shmem.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 4.x_vs_3.7.2.

    1 /* NOTE: Anywhere a sched_yield() is called, previously there was a busy
    2  * polling wait on the byte or flag, which caused horrible performance on the
    3  * machine I tested on (helix).  sched_yield() seemed to fix this issue. 
    4  */
    5 
    6 #include  "netpipe.h"
    7 
    8 double *pTime;
    9 int    *pNrepeat;
   10 
   11 void Init(ArgStruct *p, int* pargc, char*** pargv)
   12 {
   13 
   14 }
   15 
   16 void Setup(ArgStruct *p)
   17 {
   18    int npes;
   19 
   20    start_pes(2);
   21 
   22    if((npes=shmem_n_pes())!=2) {
   23 
   24       printf("Error Message: Run with npes set to 2\n");
   25       exit(1);
   26    }
   27 
   28    p->prot.flag=(int *) shmalloc(sizeof(int));
   29    pTime = (double *) shmalloc(sizeof(double));
   30    pNrepeat = (int *) shmalloc(sizeof(int));
   31 
   32    p->tr = p->rcv = 0;
   33 
   34    if((p->prot.ipe=_my_pe()) == 0) {
   35       p->tr=1;
   36       p->prot.nbor=1;
   37       *p->prot.flag=1;
   38 
   39    } else {
   40 
   41       p->rcv=1;
   42       p->prot.nbor=0;
   43       *p->prot.flag=0;
   44    }
   45 }
   46 
   47 void Sync(ArgStruct *p)
   48 {
   49    shmem_barrier_all();
   50 }
   51 
   52 void PrepareToReceive(ArgStruct *p) { }
   53 
   54 void SendData(ArgStruct *p)
   55 {
   56    if(p->bufflen%8==0)
   57       shmem_put64(p->s_ptr,p->s_ptr,p->bufflen/8,p->prot.nbor);
   58    else
   59       shmem_putmem(p->s_ptr,p->s_ptr,p->bufflen,p->prot.nbor);
   60 }
   61 
   62 void RecvData(ArgStruct *p)
   63 {
   64    int i=0;
   65 
   66    while(p->r_ptr[p->bufflen-1] != 'a' + (p->cache ? 1 - p->tr : 1) ) {
   67      sched_yield();
   68   }
   69 
   70    p->r_ptr[p->bufflen-1] = 'a' + (p->cache ? p->tr : 0);
   71 }
   72 
   73 void SendTime(ArgStruct *p, double *t)
   74 {
   75    *pTime=*t;
   76 
   77    shmem_double_put(pTime,pTime,1,p->prot.nbor);
   78    shmem_int_put(p->prot.flag,p->prot.flag,1,p->prot.nbor);
   79 }
   80 
   81 void RecvTime(ArgStruct *p, double *t)
   82 {
   83    int i=0;
   84 
   85    while(*p->prot.flag!=p->prot.ipe)
   86    {
   87      sched_yield();
   88    }
   89    *t=*pTime; 
   90    *p->prot.flag=p->prot.nbor;
   91 }
   92 
   93 void SendRepeat(ArgStruct *p, int rpt)
   94 {
   95    *pNrepeat= rpt;
   96 
   97    shmem_int_put(pNrepeat,pNrepeat,1,p->prot.nbor);
   98    shmem_int_put(p->prot.flag,p->prot.flag,1,p->prot.nbor);
   99 }
  100 
  101 void RecvRepeat(ArgStruct *p, int *rpt)
  102 {
  103    int i=0;
  104 
  105    while(*p->prot.flag!=p->prot.ipe)
  106    {
  107      sched_yield();
  108 
  109    }
  110    *rpt=*pNrepeat;
  111    *p->prot.flag=p->prot.nbor;
  112 }
  113 
  114 void  CleanUp(ArgStruct *p)
  115 {
  116 }
  117 
  118 
  119 void Reset(ArgStruct *p)
  120 {
  121 
  122 }
  123 
  124 void AfterAlignmentInit(ArgStruct *p)
  125 {
  126 
  127 }
  128 
  129 void MyMalloc(ArgStruct *p, int bufflen, int soffset, int roffset)
  130 {
  131    void* buff1;
  132    void* buff2;
  133 
  134    if((buff1=(char *)shmalloc(bufflen+MAX(soffset,roffset)))==(char *)NULL)
  135    {
  136       fprintf(stderr,"couldn't allocate memory\n");
  137       exit(-1);
  138    }
  139 
  140    if(!p->cache)
  141 
  142      if((buff2=(char *)shmalloc(bufflen+soffset))==(char *)NULL)
  143        {
  144          fprintf(stderr,"Couldn't allocate memory\n");
  145          exit(-1);
  146        }
  147 
  148    if(p->cache) {
  149      p->r_buff = buff1;
  150    } else { /* Flip-flop buffers so send <--> recv between nodes */
  151      p->r_buff = p->tr ? buff1 : buff2;
  152      p->s_buff = p->tr ? buff2 : buff1;
  153    }
  154 
  155 }
  156 void FreeBuff(char *buff1, char* buff2)
  157 {
  158   if(buff1 != NULL)
  159     shfree(buff1);
  160 
  161   if(buff2 != NULL)
  162     shfree(buff2);
  163 }