static inline void resetSweepCounter(struct localAlloc *local){
	struct allocator *alc = local->global;
	unsigned long sweep_ctr, lsweep_ctr;
	do{
		sweep_ctr=alc->sweep_counter;
		if(PHASE(sweep_ctr)>=local->localVer) return;
		assert(PHASE(sweep_ctr)==local->localVer-2);
		lsweep_ctr = MAKE_SC(0, local->localVer);
	}while(!CAS(&alc->sweep_counter, sweep_ctr, lsweep_ctr));

}
/* inverse rotate a Series buffer (multipole or local) */
static void _buffer_rotate_inverse (AranWigner * aw, guint deg,
                                    gcomplex128 *expma, gcomplex128 *expmg,
                                    gcomplex128 * src, gcomplex128 * dst)
{
  gint l, m1, m2;

  for (l = 0; l <= deg; l++)
    {
      for (m1 = 0; m1 <= l; m1++)
        {
          gcomplex128 sum = 0.;

          for (m2 = -l; m2 < 0; m2++)
            {
              gdouble wigner_term = *aran_wigner_term (aw, l, m1, m2);
              gcomplex128 src_l_m2 = src[(l * (l + 1)) / 2 + ABS (m2)];

              sum += conj (expma[m1] / expmg[ABS (m2)]) * wigner_term *
                _sph_sym (src_l_m2, ABS (m2));
            }

          for (m2 = 0; m2 <= l; m2++)
            {
              gdouble wigner_term = PHASE (m1 + m2) *
                *aran_wigner_term (aw, l, m2, m1);
              gcomplex128 src_l_m2 = src[(l * (l + 1)) / 2 + m2];

              sum += conj (expmg[m2] * expma[m1]) * wigner_term * src_l_m2;
            }

          dst[(l * (l + 1)) / 2 + m1] += sum;
        }
    }
}
Beispiel #3
0
enum sml_sync_phase
sml_current_phase()
{
	struct sml_control *control = tlv_get(current_control);
	/* Thanks to memory coherency, control->state always indicates
	 * the current status of this mutator regardless of the fact that
	 * both the mutator and collector updates it.
	 * If control->state is SYNC1, then the thread is in SYNC1.
	 */
	return PHASE(load_relaxed(&control->state));
}
Beispiel #4
0
static gdouble wigner (guint l, gint m1, gint m2, gdouble beta)
{
  gdouble ret = 0.;
  gint l_m_m1, l_p_m1, l_m_m2, l_p_m2, m1_m_m2;
  gint k, kmin, kmax;
  gdouble cb2, sb2, a;

  g_assert (ABS (m1) <= ((gint) l));
  g_assert (ABS (m2) <= ((gint) l));

  l_m_m1 = l - m1;
  l_p_m1 = l + m1;
  l_m_m2 = l - m2;
  l_p_m2 = l + m2;
  m1_m_m2 = m1 - m2;

  kmin = MAX (0, -m1_m_m2);
  kmax = MIN (l_m_m1, l_p_m2);

  if (kmin > kmax)
    return ret;

  aran_coefficient_bufferd_require (_lnfact, 2*l);

  a = (lnfact (l_p_m1) + lnfact (l_m_m1) + lnfact (l_p_m2) +
       lnfact (l_m_m2)) * 0.5;

  cb2 = cos (beta * 0.5);
  sb2 = sin (beta * 0.5);

  for (k = kmin; k <= kmax; k++)
    {
      gdouble b = lnfact (k) + lnfact (l_m_m1 - k) + lnfact (l_p_m2 - k) +
        lnfact (m1_m_m2 + k);
      gdouble c = pow (cb2, l_m_m1 + l_p_m2 - 2 * k);
      gdouble d = pow (sb2, m1_m_m2 + 2 * k);

      ret += PHASE (m1_m_m2 + k) * exp (a - b) * c * d;
    }

  return ret;
}
Beispiel #5
0
int main(int argc, char *argv[])
/* dftfold:  Does complex plane vector addition of a DFT freq */
/* Written by Scott Ransom on 31 Aug 00 based on Ransom and   */
/* Eikenberry paper I (to be completed sometime...).          */
{
   FILE *infile;
   char infilenm[200], outfilenm[200];
   int dataperread;
   unsigned long N;
   double T, rr = 0.0, norm = 1.0;
   dftvector dftvec;
   infodata idata;
   Cmdline *cmd;

   /* Call usage() if we have no command line arguments */

   if (argc == 1) {
      Program = argv[0];
      usage();
      exit(1);
   }

   /* Parse the command line using the excellent program Clig */

   cmd = parseCmdline(argc, argv);

#ifdef DEBUG
   showOptionValues();
#endif

   printf("\n\n");
   printf("        DFT Vector Folding Routine\n");
   printf("            by Scott M. Ransom\n");
   printf("              31 August, 2000\n\n");

   /* Open the datafile and read the info file */

   sprintf(infilenm, "%s.dat", cmd->argv[0]);
   infile = chkfopen(infilenm, "rb");
   readinf(&idata, cmd->argv[0]);

   /* The number of points in datafile */

   N = chkfilelen(infile, sizeof(float));
   dataperread = N / cmd->numvect;
/*   N = cmd->numvect * dataperread; */
   T = N * idata.dt;

   /* Calculate the Fourier frequency */

   if (!cmd->rrP) {
      if (cmd->ffP)
         rr = cmd->ff;
      else if (cmd->ppP)
         rr = T / cmd->pp;
      else {
         printf("\n  You must specify a frequency to fold!  Exiting.\n\n");
      }
   } else
      rr = cmd->rr;

   /* Calculate the amplitude normalization if required */

   if (cmd->normP)
      norm = 1.0 / sqrt(cmd->norm);
   else if (cmd->fftnormP) {
      FILE *fftfile;
      int kern_half_width, fftdatalen, startbin;
      double rrfrac, rrint;
      char fftfilenm[200];
      fcomplex *fftdata;

      sprintf(fftfilenm, "%s.fft", cmd->argv[0]);
      fftfile = chkfopen(fftfilenm, "rb");
      kern_half_width = r_resp_halfwidth(HIGHACC);
      fftdatalen = 2 * kern_half_width + 10;
      rrfrac = modf(rr, &rrint);
      startbin = (int) rrint - fftdatalen / 2;
      fftdata = read_fcomplex_file(fftfile, startbin, fftdatalen);
      norm = 1.0 / sqrt(get_localpower3d(fftdata, fftdatalen,
                                         rrfrac + fftdatalen / 2, 0.0, 0.0));
      vect_free(fftdata);
      fclose(fftfile);
   }

   /* Initialize the dftvector */

   init_dftvector(&dftvec, dataperread, cmd->numvect, idata.dt, rr, norm, T);

   /* Show our folding values */

   printf("\nFolding data from '%s':\n", infilenm);
   printf("   Folding Fourier Freq = %.5f\n", rr);
   printf("      Folding Freq (Hz) = %-.11f\n", rr / T);
   printf("     Folding Period (s) = %-.14f\n", T / rr);
   printf("  Points per sub-vector = %d\n", dftvec.n);
   printf("  Number of sub-vectors = %d\n", dftvec.numvect);
   printf(" Normalization constant = %g\n", norm * norm);

   /* Perform the actual vector addition */

   {
      int ii, jj;
      float *data;
      double real, imag, sumreal = 0.0, sumimag = 0.0;
      double theta, aa, bb, cc, ss, dtmp;
      double powargr, powargi, phsargr, phsargi, phstmp;

      data = gen_fvect(dftvec.n);
      theta = -TWOPI * rr / (double) N;
      dtmp = sin(0.5 * theta);
      aa = -2.0 * dtmp * dtmp;
      bb = sin(theta);
      cc = 1.0;
      ss = 0.0;
      for (ii = 0; ii < dftvec.numvect; ii++) {
         chkfread(data, sizeof(float), dftvec.n, infile);
         real = 0.0;
         imag = 0.0;
         for (jj = 0; jj < dftvec.n; jj++) {
            real += data[jj] * cc;
            imag += data[jj] * ss;
            cc = aa * (dtmp = cc) - bb * ss + cc;
            ss = aa * ss + bb * dtmp + ss;
         }
         dftvec.vector[ii].r = norm * real;
         dftvec.vector[ii].i = norm * imag;
         sumreal += dftvec.vector[ii].r;
         sumimag += dftvec.vector[ii].i;
      }
      vect_free(data);
      printf("\nDone:\n");
      printf("             Vector sum = %.3f + %.3fi\n", sumreal, sumimag);
      printf("      Total phase (deg) = %.2f\n", PHASE(sumreal, sumimag));
      printf("            Total power = %.2f\n", POWER(sumreal, sumimag));
      printf("\n");
   }
   fclose(infile);

   /* Write the output structure */

   sprintf(outfilenm, "%s_%.3f.dftvec", cmd->argv[0], rr);
   write_dftvector(&dftvec, outfilenm);

   /* Free our vector and return */

   free_dftvector(&dftvec);
   return (0);
}
Beispiel #6
0
/**
 * aran_wigner_require:
 * @aw: an #AranWigner structure.
 * @l: requested degree.
 *
 * Ensures that @aw is allocated to @l degree inclusive and that coefficients
 * are correctly computed.
 */
void aran_wigner_require (AranWigner * aw, guint l)
{
  gint i, j, k;
  gdouble cb, sb, cb2, sb2, tb2, d1_0_0, d1_1_1;

  if (((gint) l) <= aw->lmax)
    return;

  aran_wigner_realloc (aw, l);

  cb = cos (aw->beta);
  sb = sin (aw->beta);
  cb2 = cos (aw->beta * 0.5);
  sb2 = sin (aw->beta * 0.5);
  tb2 = sb2 / cb2;

  /* l == 0 */
  if (aw->lmax < 0)
    {
      aw->l_terms[0][0][0] = 1.;
      aw->lmax = 0;
    }

  if (l == 0)
    return;

  /* l == 1 */
  if (aw->lmax == 0)
    {
      aw->l_terms[1][0][1 + 0] = cb;
      aw->l_terms[1][1][1 - 1] = sb2 * sb2;
      aw->l_terms[1][1][1 + 0] = -sb / sqrt (2.);
      aw->l_terms[1][1][1 + 1] = cb2 * cb2;
      aw->l_terms[1][0][1 + 1] = -aw->l_terms[1][1][1 + 0];
      aw->l_terms[1][0][1 - 1] = aw->l_terms[1][1][1 + 0];
      aw->lmax = 1;
    }

  if (((gint) l) <= 1)
    return;

  d1_0_0 = aw->l_terms[1][0][1 + 0];
  d1_1_1 = aw->l_terms[1][1][1 + 1];

  /* l >= 2 */
  for (i = 2; i <= l; i++)
    {
      gdouble two_i_m_1 = i + i - 1.;
      gdouble sq_i = i * i;
      gdouble sq_i_m_1 = (i - 1.) * (i - 1.);

      /* j > 0, -j <= k <= j */
      for (j = 0; j <= i - 2; j++)
        {
          gdouble sq_j = j * j;

          for (k = -j; k <= j; k++)
            {
              gdouble sq_k = k * k;
              gdouble a =
                (i * two_i_m_1) / sqrt ((sq_i - sq_j) * (sq_i - sq_k));
              gdouble b = (d1_0_0 - ((j * k) / (i * (i - 1.))));
              gdouble c = sqrt ((sq_i_m_1 - sq_j) * (sq_i_m_1 - sq_k)) /
                ((i - 1.) * two_i_m_1);

              aw->l_terms[i][j][i + k] =
                a * (b * aw->l_terms[i - 1][j][(i - 1) + k] -
                     c * aw->l_terms[i - 2][j][(i - 2) + k]);
            }
        }

      /* last two diagonal terms */
      aw->l_terms[i][i][i + i] = d1_1_1 *
        aw->l_terms[i - 1][i - 1][(i - 1) + (i - 1)];

      aw->l_terms[i][i - 1][i + i - 1] = (i * d1_0_0 - i + 1.) *
        aw->l_terms[i - 1][i - 1][(i - 1) + (i - 1)];

      /* last column terms */
      for (k = i; k >= 1 - i; k--)
        {
          aw->l_terms[i][i][i + k - 1] = -sqrt ((i + k) / (i - k + 1.)) * tb2 *
            aw->l_terms[i][i][i + k];
        }

      /* penultimate column */
      for (k = i - 1; k > 0; k--)
        {
          gdouble i_cb = i * cb;
          gdouble a = ((i_cb - k + 1.) / (i_cb - k));

          aw->l_terms[i][i - 1][i + k - 1] =
            -a * sqrt ((i + k) / (i - k + 1.)) *
            tb2 * aw->l_terms[i][i - 1][i + k];
        }

      /* we cut [i][i - 1] k loop in order to avoid problems for k==0 when
       * beta == pi/2.
       */
      aw->l_terms[i][i - 1][i + 0] = -sqrt (2. * (two_i_m_1) / (i - 1.)) *
        cb2 * sb2 * aw->l_terms[i - 1][i - 2][(i - 1) + 0];

      /* remaining of penultimate column */
      for (k = 0; k >= 2 - i; k--)
        {
          gdouble i_cb = i * cb;
          gdouble a = ((i_cb - k + 1.) / (i_cb - k));

          aw->l_terms[i][i - 1][i + k - 1] =
            -a * sqrt ((i + k) / (i - k + 1.)) *
            tb2 * aw->l_terms[i][i - 1][i + k];
        }

      /* extra diagonal terms (|k| > j) */
      for (k = 1; k <= i; k++)
        {
          for (j = 0; j < k; j++)
            {
              aw->l_terms[i][j][i + k] = PHASE (j + k) *
                aw->l_terms[i][k][i + j];
              aw->l_terms[i][j][i - k] = aw->l_terms[i][k][i - j];
            }
        }
    }

  aw->lmax = l;
}
Beispiel #7
0
void main( int argc, char **argv) {
    char match; 
    char **remArgs;
    int  rv;

    GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
    float                scrWidth   = 640.0f;
    float                scrHeight  = 480.0f;
#define NVERT 5
    GrVertex vtx[NVERT];
    int index[NVERT];
    int frames                      = -1;
    int i, idx;
#define NHUE 360
    RGB hues[NHUE];
    FxU32 wrange[2];
    GrContext_t          gc = 0;
    
    /* Initialize Glide */
    grGlideInit();
    assert( hwconfig = tlVoodooType() );

    /* Process Command Line Arguments */
    while( rv = tlGetOpt( argc, argv, "nr", &match, &remArgs ) ) {
        if ( rv == -1 ) {
            printf( "Unrecognized command line argument\n" );
            printf( "%s %s\n", name, usage );
            printf( "Available resolutions:\n%s\n",
                    tlGetResolutionList() );
            return;
        }
        switch( match ) {
        case 'n':
            frames = atoi( remArgs[0] );
            break;
        case 'r':
            resolution = tlGetResolutionConstant( remArgs[0], 
                                                  &scrWidth, 
                                                  &scrHeight );
            break;
        }
    }

    tlSetScreen( scrWidth, scrHeight );

    version = grGetString( GR_VERSION );

    printf( "%s:\n%s\n", name, purpose );
    printf( "%s\n", version );
    printf( "Resolution: %s\n", tlGetResolutionString( resolution ) );
    if ( frames == -1 ) {
        printf( "Press A Key To Begin Test.\n" );
        tlGetCH();
    }
    
    grSstSelect( 0 );
    gc = grSstWinOpen(tlGethWnd(),
                      resolution,
                      GR_REFRESH_60Hz,
                      GR_COLORFORMAT_ABGR,
                      GR_ORIGIN_UPPER_LEFT,
                      2, 1 );
    if (!gc) {
      printf("Could not allocate glide fullscreen context.\n");
      goto __errExit;
    }
    
    tlConSet( 0.0f, 0.0f, 1.0f, 1.0f, 
              60, 30, 0xffffff );

    /* Set up Render State - gouraud shading */
    grGet(GR_WDEPTH_MIN_MAX, 8, (FxI32 *)wrange);  
    grVertexLayout(GR_PARAM_XY,  0, GR_PARAM_ENABLE);
    grVertexLayout(GR_PARAM_RGB, GR_VERTEX_R_OFFSET << 2, GR_PARAM_ENABLE);

    grColorCombine( GR_COMBINE_FUNCTION_LOCAL,
                    GR_COMBINE_FACTOR_NONE,
                    GR_COMBINE_LOCAL_ITERATED,
                    GR_COMBINE_OTHER_NONE,
                    FXFALSE );

    tlConOutput( "Press a key to quit\n" );

    /* init a table of hues */
    for (i=0; i<NHUE; i++) {
      const float theta = i * 360.0f / NHUE;
      hlsToRGB( theta, 0.4f, 0.5f, &hues[i]);
    }

    /* assign hues to vertices */
    for (i=0; i<NVERT; i++) {
        vtx[i].r = hues[PHASE(0, i*(NHUE / NVERT), NHUE)].r;
        vtx[i].g = hues[PHASE(0, i*(NHUE / NVERT), NHUE)].g;
        vtx[i].b = hues[PHASE(0, i*(NHUE / NVERT), NHUE)].b;
    }
#if 1
    /*
     * Force polygon RGB values to be planar... note overflow!
     * this is deliberate as a sanity check
     */
    vtx[3].r = 235.519f; vtx[3].g = 51.001f; vtx[3].b = 115.721f;
    vtx[4].r = 298.559f; vtx[4].g = -12.039f; vtx[4].b = 91.0f;
#endif

    while( frames-- && tlOkToRender()) {

        tlGetDimsByConst(resolution,
                         &scrWidth, 
                         &scrHeight );
        
        grClipWindow(0, 0, (FxU32) scrWidth, (FxU32) scrHeight);

        grBufferClear( 0x00, 0, wrange[1] );

        /* generate a equilateral polygon */
        for (i=0; i<NVERT; i++) {
          double theta = 2.0 * PI * i / (double) NVERT;
          
          vtx[i].x = tlScaleX((float)((cos(theta) / 4.0) + 0.5));
          vtx[i].y = tlScaleY((float)((sin(theta) / 4.0) + 0.5));
          
          index[i] = i;
        }

        idx = 30 /* (-frames) % NHUE */;

#if 1
        /* cyclical permutation: turn off to see just one set of triangles */
        for (i=0; i<NVERT; i++) {
            index[i] = (index[i] + 1) % NVERT;
        }
#endif

        grDrawVertexArrayContiguous(GR_POLYGON, NVERT, vtx, sizeof(GrVertex));

        tlConRender();
        grBufferSwap( 1 );
        if ( tlKbHit() ) frames = 0;
    }

 __errExit:    
    grGlideShutdown();
    return;
}
Beispiel #8
0
void HaploWindow::reportPhase()
{
  string fn = par::output_file_name+".phase";
  ofstream PHASE(fn.c_str(), ios::out);

  //P.printLOG("Writing phased haplotypes for " + hname + " to [ "+ fn + " ]\n");

  cout << setw(12) << "FID"<< " "<< setw(12) << "IID"<< " "<< setw(4)<< "PH"
       << " "<< setw(10) << "HAP1"<< " "<< setw(10) << "HAP2"<< " "
       << setw(12) << "POSTPROB"<< " "<< setw(6) << "BEST"<< " "<< "\n";

  PHASE.precision(4);

  for (int i = 0; i < haplo->P.n; i++)
    {

      if (haplo->include[i])
	{

	  for (int z = 0; z < hap1[i].size(); z++)
	    {

	      cout << setw(12) << haplo->P.sample[i]->fid<< " "<< setw(12)
		   << haplo->P.sample[i]->iid<< " "<< setw(4) << z << " "
		   << setw(10) << haplotypeName(hap1[i][z]) << " ";

	      if (haplo->haploid || (haplo->X && haplo->P.sample[i]->sex))
		cout << setw(10) << haplotypeName( -1) << " ";
	      else
		cout << setw(10) << haplotypeName(hap2[i][z]) << " ";

	      if (ambig[i])
		{
		  cout << setw(12) << pp[i][z]<< " ";

		  int max_z = 0;
		  for (int z2=0; z2<hap1[i].size(); z2++)
		    max_z = pp[i][z2] > pp[i][max_z] ? z2 : max_z ;

		  // 		  int fac=1;
		  // 		  if ( hap1[i][max_z] != hap2[i][max_z] ) fac=2;
		  // 		  double w = ( pp[i][max_z] - fac*f[hap1[i][max_z]]*f[hap1[i][max_z]] ) 
		  // 		    / ( 1 - fac*f[hap1[i][max_z]]*f[hap1[i][max_z]] );

		  // Do not output weight for now
		  // if (max_z==z) PHASE << setw(12) << w << " " << setw(6) << 1 << " " << "\n";
		  // else PHASE << setw(12) << "."  << " " << setw(6) << 0  << " " << "\n";

		  if (max_z == z)
		    cout << setw(6) << 1<< " "<< "  ";
		  else
		    cout << setw(6) << 0<< " "<< "  ";
		}
	      else
		cout << setw(12) << 1<< " "<< setw(6) << 1<< " "<< "  ";

	      // Genotypes
	      //for (int s=0; s<ns; s++)
	      //	PHASE << genotype(P, i, S[s]) << " ";
	      cout << "\n";

	    }
	}

      // Report also on excluded individuals
      // (Should be 0-size phase-set)
      else
	{

	  cout << setw(12) << haplo->P.sample[i]->fid<< " "<< setw(12)
	       << haplo->P.sample[i]->iid<< " "<< setw(4) << "NA"<< " "
	       << setw(10) << "NA"<< " "<< setw(10) << "NA"<< " "
	       << setw(12) << "NA"<< " "<< setw(6) << "NA"<< "   ";

	  // genotypes
	  //for (int s=0; s<ns; s++)
	  //	PHASE << genotype(P, i, S[s]) << " ";
	  cout << "\n";

	}
    }

  PHASE.close();

}