Exemplo n.º 1
0
main(int argc, char **argv)
{
    int i,j;
    int c;
    extern char *optarg;
    int ctrproc;
    int start;
    int proc_size;
    char name[32];

    /*********************************************************************
      Parse the command line
      ********************************************************************/
    collect_info = 1;
    MEMSYS_OFF;                             /* in the initialization phase */
    while ((c = getopt(argc, argv, "p:s:b:BdvH")) != -1) {
        switch(c) {
        case 'p':
            NUM_PROCS = atoi(optarg);
            if (NUM_PROCS < 1) {
                printf("P must be >= 1\n");
                exit(-1);
            }
            break;

        case 's':
            size = atoi(optarg);
            break;

        case 'b':
            BubbleThresh = atoi(optarg);
            break;

        case 'B':
            bubble = 1;
            break;
        case 'd':
            show_array = 1;
            break;
        case 'v':
            verify = 1;
            break;
        default:
            printf("Bad option : %s \n",optarg);
        case 'h':
            printf( "\t\t\tQS - OPTIONS\n");
            printf( "\tp - Number of processors\n");
            printf( "\ts - Size of array\n");
            printf( "\tb - Bubble threshold\n");
            printf( "\tB - Bubble\n");
            printf( "\td - Display output \n");
            printf( "\tv - Verify results \n");
            printf( "\tH - Help\n");
            exit(0);
        }
    }

    StatClearAll();         /* clear the stats */
    /**********************************************************************/
    /* Use shmalloc to allocate memory from the shared address space, also
       use AssociateAddrNode to determine the distribution of the shared
       memory among the various processors */
    /**********************************************************************/
    gMem = (GlobalMemory *) shmalloc(sizeof(GlobalMemory));
    ctrproc = NUM_PROCS/2  + (int)(sqrt((double)NUM_PROCS)/2);
    /* choose a "middle-point" in the mesh network */

    /* associate the task stack variables to a processor easily accessible */
#if !defined(SPATIAL)
    AssociateAddrNode((void *)&(gMem->TaskStackLock),
                      (void *)(&(gMem->NumWaiting)+1),
                      ctrproc>=NUM_PROCS-1? NUM_PROCS-1 :  ctrproc+1,"lock");
    AssociateAddrNode((void *)&(gMem->TaskStackTop),
                      (void *)(&(gMem->TaskStackTop)+1),
                      ctrproc>=NUM_PROCS-1 ? NUM_PROCS-1 : ctrproc,"top");
#endif

    /************** associate the task queue among all processors *********/
    chunk = MAX_TASK_QUEUE / NUM_PROCS;
    for (i=0; i< NUM_PROCS; i++)   {
#if !defined(SPATIAL)
        AssociateAddrNode(&gMem->tasks[i*chunk],
                          &gMem->tasks[(i+1)*chunk],
                          i,"tasks");
#endif
    }
    LocalStackTop = -1;
    FREELOCK(&gMem->TaskStackLock);
    proc_size = (size + NUM_PROCS)/NUM_PROCS;

    /*************** associate the array among all processors **************/
    start = 0;
    strcpy(name,"Array chunks");
    for(i=0; i<NUM_PROCS; i++) {
        printf("going to call Associate address node\n");
#if !defined(SPATIAL)&&!defined(DO_PREF)
        AssociateAddrNode(&gMem->A[start],
                          &gMem->A[start+ proc_size],
                          i, name);
#endif
        start = start+proc_size;
    }

    printf( "QS - OPTIONS\n");
    printf( "\tp - Number of processors \t%d\n", NUM_PROCS);
    printf( "\ts - Size of array\t\t%d\n",size);
    printf( "\tb - Bubble threshold \t\t%d\n",BubbleThresh);
    printf( "\tB - Bubble \t\t\t%d\n",bubble);
    printf( "\td - Display output\t\t%d\n",show_array);
    printf( "\tv - Verify results\t\t%d\n",verify);

    /* The work which the root process has to do */
    whoami=0;
    root_main();                  /* initialization by the root process */
    endphase(phase);              /* end of initialization phase */
    TreeBarInit(&tree,NUM_PROCS); /* initialize tree barrier */

    MEMSYS_ON;

    /********************************************************************/
    /* Forking processes :  Create a process for each of the processors */
    /********************************************************************/

    for(i=0; i<NUM_PROCS-1; i++) {
        if(fork() == 0)     {
            whoami =  getpid();
            LocalStackTop = -1;
            for (i = (whoami+1) * chunk -1; i > whoami * chunk; i--) {
                LocalTaskStack[++LocalStackTop] = i;
            }
            break;
        }
    }

    /******************* Barrier after initialization *******************/
    printf("Before barrier %d\n",whoami);
    TreeBarrier(&tree,whoami);
    printf("Starting Process %d\n",whoami);
    if (whoami == 0)     {
        StatReportAll();
        StatClearAll();
    }

    newphase(++phase);
    Worker();   /**** Call the main procedure which we have to execute ****/
    endphase(phase);

    /**************** Barrier after finishing the sort ******************/
    printf("Coming out of worker %d\n",whoami);
    TreeBarrier(&tree,whoami);
    MEMSYS_OFF;
    if (whoami == 0)     {
        StatReportAll();
        StatClearAll();
    }

    /*************************** Cleanup phase ***************************/
    newphase(++phase);
    if(whoami== 0)     do_cleanup();
    endphase(phase);
    if (whoami == 0)     {
        StatReportAll();
        StatClearAll();
    }
}
Exemplo n.º 2
0
void calpolycoeff(int np,int nf,int si,float fov,float dt,float *wbuff1,float *wbuff0,float *a0,float *a,float *b,float *c, float *chisq, int nn)
  {
  double x, ia, sum_xy,sum_xx,sum_y,sum_x2y,sum_x4, sum_x3y, sum_x6;
  int   offset,off1,i,j;
  float  temp;
  char logfile[255];
  FILE *fp;

    offset = 2*np+2+2*(nf-1)*si+1; /*+2 for writing in imaginary part +1 for real part of spc*/   
    off1 = (2*nf-1)*(si/2);

    sum_xy = 0;
    sum_xx = 0;
    for (i = -np; i<np+1; i++) 
    {
      wbuff0[2*i-1+offset] = wbuff1[2*i+off1];
      wbuff0[2*i+offset] = wbuff1[2*i+off1+1];
    }
    i = 0;
    x = (1.0*i)/np;

fprintf(stderr,"Value of np : %d\n", np);

    sum_y = (double)wbuff0[2*i-1+offset];
    sum_xy = (double)(x*(wbuff0[2*i-1+offset]));
    sum_xx = (x*x);
    sum_x2y = x*sum_xy;
    sum_x4 = (sum_xx*sum_xx);
    sum_x6 = sum_xx*sum_x4;
    sum_x3y = x*sum_x2y;
    j=1;
    while ((j<np+1) && (wbuff0[2*j+offset]>0) && (wbuff0[-2*j+offset]>0))
    {
      i = j;
      x = (1.0*i)/np;
      wbuff0[2*i-1+offset] = newphase(wbuff0[2*(i-1)-1+offset],wbuff0[2*i-1+offset]);
      sum_y = (double)wbuff0[2*i-1+offset]+sum_y;
      sum_xy = (double)(x*(wbuff0[2*i-1+offset]))+sum_xy;
      sum_xx = x*x+sum_xx;
      sum_x2y = (double)(x*x*(wbuff0[2*i-1+offset]))+sum_x2y;
      sum_x4 = x*x*x*x+sum_x4;
      sum_x3y = (double)(x*x*x*wbuff0[2*i-1+offset])+sum_x3y;
      sum_x6 = x*x*x*x*x*x+sum_x6;
      i=-j;
      x = (1.0*i)/np;
      wbuff0[2*i-1+offset] = newphase(wbuff0[2*(i+1)-1+offset],wbuff0[2*i-1+offset]);
      sum_y = (double)wbuff0[2*i-1+offset]+sum_y;
      sum_xy = (double)(x*(wbuff0[2*i-1+offset]))+sum_xy;
      sum_xx = x*x+sum_xx;
      sum_x2y = (double)(x*x*(wbuff0[2*i-1+offset]))+sum_x2y;
      sum_x4 = x*x*x*x+sum_x4;
      sum_x3y = (double)(x*x*x*wbuff0[2*i-1+offset])+sum_x3y;
      sum_x6 = x*x*x*x*x*x+sum_x6;
      j=j+1;
    }
    np=j-1;
    *a0 = (float)((sum_y)/((2*np+1)));
    *a = 0.0;
    *b = 0.0;
    *c = 0.0;

    if (np<minpoints)
    {
      *chisq = 1000.0;
    }
    else
    {
    if (nn>1)
    {
    *a0 = (float)((sum_xx*sum_x2y-sum_y*sum_x4)/((sum_xx*sum_xx)-(2*np+1)*sum_x4));
    *b = (float)((sum_xx*sum_y-(2*np+1)*sum_x2y)/((sum_xx*sum_xx)-(2*np+1)*sum_x4));
     }
    if ((nn<3) && (nn>0))
    {
     *a = (float)(sum_xy)/(sum_xx);
    *c = 0.0;
     }
    if (nn>2) 
    {
     *a = (float)(sum_x3y*sum_x4-sum_xy*sum_x6)/(sum_x4*sum_x4-sum_xx*sum_x6);
     *c = (float)((sum_xy*sum_x4-sum_x3y*sum_xx)/(sum_x4*sum_x4-sum_x6*sum_xx));
    }
    *chisq=0.0;

    for (i = -np; i<np+1; i++) 
    {
      wbuff0[2*i-1+offset+si] = wbuff0[2*i-1+offset]-(*a0+i*(*a)/np+SQR(1.0*i/np)*(*b)+i*(*c)/np*SQR(1.0*i/np));
      *chisq = *chisq+(wbuff0[2*i-1+offset+si]*wbuff0[2*i-1+offset+si]);
/*wbuff0[2*i+offset+si] for writing in imaginary part wbuff0[2*i-1+offset+si] for real part of spc*/
    }
  /*Scaling:
    =======
    for x=-1..1; 
    x:  ((np/si)*SW/(1000*G)) for G = Gradient in [1000Hz/cm], e.g. 1
        i.e. (np*FOV/si)
    nu: 1/(360*T) for T = extra delay in [10ms], hence dt*1e2 e.g. 
  */

    *a = (*a)*(si/(2*fov*np*360e-6*dt*1.0e2));
    *b = (*b)*SQR(si/(2*fov*np))/(360e-6*dt*1.0e2);
    *c = (*c)*si/(2*fov*np*360e-6*dt*1.0e2)*SQR(si/(2*fov*np));
    *a0 = *a0/(360e-6*dt*1.0e2);
    *chisq = sqrt(*chisq)/((360e-6*dt*1.0e2)*(2.0*np+1));
    }

    strcpy(logfile,getenv("vnmruser"));
    strcat(logfile,"/shims/fastmap.log");
    fp = fopen(logfile,"a");
    fprintf(fp,"%+5.1f %+5.2f %+4.2f %+5.3f (%+3.2f) \n",*a0,*a,*b,*c,*chisq);
    fclose(fp);
    fprintf(stderr,"%+5.1f %+5.2f %+4.2f %+5.3f (%+3.2f) \n",*a0,*a,*b,*c,*chisq);
  }/*calpolycoeff*/