"Fossies" - the Fresh Open Source Software Archive

Member "NetPIPE-3.7.2/src/gpshmem.c" (19 Aug 2010, 2611 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 "gpshmem.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 #include  "netpipe.h"
    2 
    3 extern double *pTime;
    4 extern int    *pNrepeat;
    5 
    6 void Init(ArgStruct *p, int* pargc, char*** pargv)
    7 {
    8    gpshmem_init(pargc, pargv);
    9 }
   10 
   11 void Setup(ArgStruct *p)
   12 {
   13    int npes;
   14 
   15    if((npes=gpnumpes())!=2) {
   16 
   17       printf("Error Message: npes = %d - You must run on 2 nodes\n", gpnumpes());
   18       exit(1);
   19    }
   20 
   21    p->prot.flag=(int *) gpshmalloc(sizeof(int));
   22    pTime = (double *) gpshmalloc(sizeof(double));
   23    pNrepeat = (int *) gpshmalloc(sizeof(int));
   24 
   25    p->tr = p->rcv = 0;
   26    if((p->prot.ipe=gpmype()) == 0) {
   27       p->tr=1;
   28       p->prot.nbor=1;
   29       *p->prot.flag=1;
   30 
   31    } else {
   32 
   33       p->rcv=1;
   34       p->prot.nbor=0;
   35       *p->prot.flag=0;
   36    }
   37 }
   38 
   39 void Sync(ArgStruct *p)
   40 {
   41    gpshmem_barrier_all();
   42 }
   43 
   44 void PrepareToReceive(ArgStruct *p) { }
   45 
   46 void SendData(ArgStruct *p)
   47 {
   48    if(p->bufflen%4==0)
   49       gpshmem_put32((short*)p->buff,(short*)p->buff,p->bufflen/4,p->prot.nbor);
   50    else
   51       gpshmem_putmem(p->buff,p->buff,p->bufflen,p->prot.nbor);
   52 }
   53 
   54 void RecvData(ArgStruct *p)
   55 {
   56    int i=0;
   57 
   58    while( p->buff[p->bufflen-1] != 'b'+p->prot.ipe ) {
   59 
   60       if( ++i%10000000==0 ) printf(""); 
   61 
   62    }
   63 
   64    p->buff[p->bufflen-1] = 'b' + p->prot.nbor; 
   65 }
   66 
   67 void SendTime(ArgStruct *p, double *t)
   68 {
   69    *pTime=*t;
   70 
   71    gpshmem_putmem(pTime,pTime,sizeof(double),p->prot.nbor);
   72    gpshmem_putmem(p->prot.flag,p->prot.flag,sizeof(int),p->prot.nbor);
   73 }
   74 
   75 void RecvTime(ArgStruct *p, double *t)
   76 {
   77    int i=0;
   78 
   79    while(*p->prot.flag!=p->prot.ipe)
   80    {
   81       if(++i%10000000==0) printf("");
   82    }
   83    *t=*pTime; 
   84    *p->prot.flag=p->prot.nbor;
   85 }
   86 
   87 void SendRepeat(ArgStruct *p, int rpt)
   88 {
   89    *pNrepeat= rpt;
   90 
   91    gpshmem_putmem(pNrepeat,pNrepeat,sizeof(int),p->prot.nbor);
   92 
   93    gpshmem_putmem(p->prot.flag,p->prot.flag,sizeof(int),p->prot.nbor);
   94 
   95 }
   96 
   97 void RecvRepeat(ArgStruct *p, int *rpt)
   98 {
   99    int i=0;
  100 
  101    while( *p->prot.flag != p->prot.ipe ) {
  102 
  103       if( ++i%2 == 3 ) printf("%d", *p->prot.flag);  /* invalidate cache */
  104 
  105    }
  106    *rpt=*pNrepeat;
  107    *p->prot.flag=p->prot.nbor;
  108 
  109 }
  110 
  111 void CleanUp(ArgStruct *p)
  112 {
  113    gpshmem_finalize();
  114 }
  115 
  116 
  117 void Reset(ArgStruct *p)
  118 {
  119 
  120 }
  121 
  122 void MyMalloc(ArgStruct *p, int bufflen, int soffset, int roffset)
  123 {
  124    if((p->buff=(char *)gpshmalloc(bufflen+MAX(soffset,roffset)))==(char *)NULL)
  125    {
  126       fprintf(stderr,"couldn't allocate memory\n");
  127       exit(-1);
  128    }
  129    p->buff[bufflen-1]='b'+p->tr;
  130    if((p->buff1=(char *)gpshmalloc(bufflen+soffset))==(char *)NULL)
  131    {
  132       fprintf(stderr,"Couldn't allocate memory\n");
  133       exit(-1);
  134    }
  135    return 0;
  136 }      
  137 void FreeBuff(char *buff1, char* buff2)
  138 {        
  139    gpshfree(buff1);
  140    gpshfree(buff2);
  141 }  
  142