Пример #1
0
void frand(_MIPD_ flash x)
{ /* generates random flash number 0<x<1 */
    int i;
#ifdef MR_FP
    mr_small dres;
#endif
#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif
    if (mr_mip->ERNUM) return;

    MR_IN(46)

    zero(mr_mip->w6);
    mr_mip->w6->len=mr_mip->nib;
    for (i=0;i<mr_mip->nib;i++) 
    { /* generate a full width random number */
        if (mr_mip->base==0) mr_mip->w6->w[i]=brand(_MIPPO_ );
        else                 mr_mip->w6->w[i]=MR_REMAIN(brand(_MIPPO_ ),mr_mip->base);
    }
    mr_mip->check=OFF;
    bigrand(_MIPP_ mr_mip->w6,mr_mip->w5);
    mr_mip->check=ON;
    mround(_MIPP_ mr_mip->w5,mr_mip->w6,x);

    MR_OUT
}
    /// Add everything from an object database, swaying positions.
    ///
    /// \param db Database.
    /// \param amplitude Swaying amplitudes.
    /// \param phase Current phase.
    /// \param block_size Block size, objects in same block are considered to be in same phase.
    /// \param pass Render pass id.
    void addObjectDatabaseSwaying(const ObjectDatabase &db, const vec3 &amplitude, float phase,
        unsigned block_size, unsigned pass = 0)
    {
      for(unsigned ii = 0; (ii < db.getObjectCount()); ++ii)
      {
        const Object& obj = db.getObject(ii);

        bsd_srand(ii / block_size);

        float px = frand(-amplitude[0], amplitude[0]);
        float py = frand(-amplitude[1], amplitude[1]);
        float pz = frand(-amplitude[2], amplitude[2]);
        float ax = frand(static_cast<float>(M_PI));
        float ay = frand(static_cast<float>(M_PI));
        float az = frand(static_cast<float>(M_PI));
       
        px *= dnload_sinf(ax + phase * (brand() ? -1.0f : 1.0f));
        py *= dnload_sinf(ay + phase * (brand() ? -1.0f : 1.0f));
        pz *= dnload_sinf(az + phase * (brand() ? -1.0f : 1.0f));

        mat4 tr = obj.unpackTransform(m_frame);

        tr[12] += px;
        tr[13] += py;
        tr[14] += pz;

        addObject(obj, tr, pass);
      }
    }
Пример #3
0
void genmatrix(int seed)
{
	bseed(seed);
	int i;
	for (i = 0; i < MAXDIM*MAXDIM; ++i) {
		a[i] = brand() % 2000 + 1000;
		b[i] = brand() % 2000 + 1000;
	}
}
Пример #4
0
void Builder::pack(Node* node, char* file)
{
    brand( node, &file );

    if( node->left() ) {
        pack( node->left(), file );
    }
    brand( node->left(), &file );

    if( node->right() ) {
        pack( node->right(), file );
    }
    brand( node->right(), &file );
}
Пример #5
0
int main()
{
  int prize, choice, show, notshown, newchoice;
  int staywinning=0, changewinning=0, randomwinning=0;
  int odoor[2];
  int i,j,k;
  
  for(i=0; i &lt; TRIALS; i++)
  {
     /* put the prize somewhere */
     prize = brand(3);
     /* let the user choose a door */
     choice = brand(3);
     /* let us take a list of unchoosen doors */
     for (j=0, k=0; j&lt;3; j++)
     {
        if (j!=choice) odoor[k++] = j;
     }
     /* Monty opens one... */
     if ( choice == prize )
     { /* staying the user will win... Monty opens a random
          port*/
       show = odoor[ brand(2) ];
       notshown = odoor[ (show+1)%2 ];
     } else { /* no random, Monty can open just one door... */
       if ( odoor[0] == prize )
       {
           show = odoor[1];
           notshown = odoor[0];
       } else {
           show = odoor[0];
           notshown = odoor[1];
       }
     }
     
     /* the user randomly choose one of the two closed doors
        (one is his/her previous choice, the second is the
        one notshown */
     odoor[0] = choice;
     odoor[1] = notshown;
     newchoice = odoor[ brand(2) ];
     /* now let us count if it takes it or not */
     if ( choice == prize ) staywinning++;
     if ( notshown == prize ) changewinning++;
     if ( newchoice == prize ) randomwinning++;
  }
  
  printf(&quot;Staying: %.2f\n&quot;, PERCENT(staywinning) );
Пример #6
0
static ca_context*
ca_context_get_default()
{
    // This allows us to avoid race conditions with freeing the context by handing that
    // responsibility to Glib, and still use one context at a time
    static GStaticPrivate ctx_static_private = G_STATIC_PRIVATE_INIT;

    ca_context* ctx = (ca_context*) g_static_private_get(&ctx_static_private);

    if (ctx) {
        return ctx;
    }

    ca_context_create(&ctx);
    if (!ctx) {
        return nullptr;
    }

    g_static_private_set(&ctx_static_private, ctx, (GDestroyNotify) ca_context_destroy);

    GtkSettings* settings = gtk_settings_get_default();
    if (g_object_class_find_property(G_OBJECT_GET_CLASS(settings),
                                     "gtk-sound-theme-name")) {
        gchar* sound_theme_name = nullptr;
        g_object_get(settings, "gtk-sound-theme-name", &sound_theme_name, NULL);

        if (sound_theme_name) {
            ca_context_change_props(ctx, "canberra.xdg-theme.name", sound_theme_name, NULL);
            g_free(sound_theme_name);
        }
    }

    nsCOMPtr<nsIStringBundleService> bundleService =
        mozilla::services::GetStringBundleService();
    if (bundleService) {
        nsCOMPtr<nsIStringBundle> brandingBundle;
        bundleService->CreateBundle("chrome://branding/locale/brand.properties",
                                    getter_AddRefs(brandingBundle));
        if (brandingBundle) {
            nsAutoString wbrand;
            brandingBundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(),
                                              getter_Copies(wbrand));
            NS_ConvertUTF16toUTF8 brand(wbrand);

            ca_context_change_props(ctx, "application.name", brand.get(), NULL);
        }
    }

    nsCOMPtr<nsIXULAppInfo> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
    if (appInfo) {
        nsAutoCString version;
        appInfo->GetVersion(version);

        ca_context_change_props(ctx, "application.version", version.get(), NULL);
    }

    ca_context_change_props(ctx, "application.icon_name", MOZ_APP_NAME, NULL);

    return ctx;
}
Пример #7
0
/**
 * \brief A bit-twiddling load which will run within the given bytes of memory.
 * \param [in] plan The struct that holds the plan's data values.
 * \return int Error flag value
 * \sa parseCBAPlan
 * \sa makeCBAPlan
 * \sa initCBAPlan
 * \sa perfCBAPlan
 * \sa killCBAPlan
 */
int execCBAPlan(void *plan){
    #ifdef HAVE_PAPI
    int k;
    long long start, end;
    #endif //HAVE_PAPI

    int i, j;
    int niters;
    ORB_t t1, t2;
    Plan *p;
    CBA_data *ci;

    p = (Plan *)plan;
    ci = (CBA_data *)p->vptr;

    /* update execution count */
    p->exec_count++;

    for(i = 0; i < ci->niter; i += NITERS){
        niters = ci->niter - i;
        if(niters > NITERS){
            niters = NITERS;
        }

        for(j = 0; j < niters; j++){
            /* pick NITERS random rows in the range 1..(nrow-1) */
            ci->out[j] = 1 + (brand(&(ci->br)) % (ci->nrows - 1));
            ci->out[j] <<= 48;              /* store index in high 16 bits */
        }

        if(DO_PERF){
            #ifdef HAVE_PAPI
            /* Start PAPI counters and time */
            TEST_PAPI(PAPI_reset(p->PAPI_EventSet), PAPI_OK, MyRank, 9999, PRINT_SOME);
            start = PAPI_get_real_usec();
            #endif //HAVE_PAPI

            ORB_read(t1);
        }         //DO_PERF
        cnt_bit_arr (ci->work, ci->nrows, ci->ncols, ci->out, niters);
        if(DO_PERF){
            ORB_read(t2);

            #ifdef HAVE_PAPI
            end = PAPI_get_real_usec();             //PAPI time

            /* Collect PAPI counters and store time elapsed */
            TEST_PAPI(PAPI_accum(p->PAPI_EventSet, p->PAPI_Results), PAPI_OK, MyRank, 9999, PRINT_SOME);
            for(k = 0; k < p->PAPI_Num_Events && k < TOTAL_PAPI_EVENTS; k++){
                p->PAPI_Times[k] += (end - start);
            }
            #endif //HAVE_PAPI

            perftimer_accumulate(&p->timers, TIMER0, ORB_cycles_a(t2, t1));
        }         //DO_PERF
    }

    return ERR_CLEAN;
} /* execCBAPlan */
Пример #8
0
int main()
{ /* program to find a trap-door prime */
    BOOL found;
    int i,spins;
    long seed;
    big pp[NPRIMES],q,p,t;
    FILE *fp;
    mirsys(50,0);
    for (i=0;i<NPRIMES;i++) pp[i]=mirvar(0);
    q=mirvar(0);
    t=mirvar(0);
    p=mirvar(0);
    printf("Enter 9 digit seed= ");
    scanf("%ld",&seed);
    getchar();
    irand(seed);
    printf("Enter 4 digit seed= ");
    scanf("%d",&spins);
    getchar();
    for (i=0;i<spins;i++) brand();
    convert(2,pp[0]);
    do
    {  /* find prime p = 2.pp[1].pp[2]....+1 */
        convert(2,p);
        for (i=1;i<NPRIMES-1;i++)
        { /* generate all but last prime */
            bigdig(i+6,10,q);
            nxprime(q,pp[i]);
            multiply(p,pp[i],p);
        }
        do
        { /* find last prime component such that p is prime */
            nxprime(q,q);
            copy(q,pp[NPRIMES-1]);
            multiply(p,pp[NPRIMES-1],t);
            incr(t,1,t);
        } while(!isprime(t));
        copy(t,p);
        found=TRUE;
        for (i=0;i<NPRIMES;i++)
        { /* check that PROOT is a primitive root */
            decr(p,1,q);
            divide(q,pp[i],q);
            powltr(PROOT,q,p,t);
            if (size(t)==1) 
            {
                found=FALSE;
                break;
            }
        }
    } while (!found);
    fp=fopen("prime.dat","wt");
    fprintf(fp,"%d\n",NPRIMES);
    for (i=0;i<NPRIMES;i++) cotnum(pp[i],fp);
    fclose(fp);
    printf("prime= \n");
    cotnum(p,stdout);
    return 0;
}
Пример #9
0
int main(void)
{
	Sorcerer brand("brand", "the Magnificent");
	Victim daniel("Daniel");
	Peon Grunt("Grunt");
	std::cout << brand << daniel << Grunt;
	brand.polymorph(daniel);
	brand.polymorph(Grunt);
	return 0;
}
 /// Randomize a fade-in direction based on coordinate itself.
 ///
 /// \param coord Coordinate value.
 /// \param diff Difference value.
 /// \return Coordinate value coming from correct direction.
 static float randomOffsetCoord(float coord, float diff)
 {
   if(coord < 0.0f)
   {
     return coord - diff;
   }
   else if(coord > 0.0f)
   {
     return coord + diff;
   }
   return brand(-1.0f, 1.0f) * diff;
 }
Пример #11
0
void genmatrix(int seed)
{
	bseed(seed);
	int i;
	for (i = 0; i < n; ++i) {
		int j;
		for (j = 0; j < n; ++j) {
			VAL(A, i, j) = brand() % 2000;
#if CHECK_CORRECTNESS
			VAL(Orig, i, j) = VAL(A, i, j);
#endif
		}
	}
}
Пример #12
0
int main()
{ /* program to find a trap-door prime */
    BOOL found;
    int i,spins;
    long seed;
    Big pp[NPRIMES],q,p,t;
    ofstream prime_data("prime.dat");
    cout << "Enter 9 digit seed= ";
    cin >> seed;
    irand(seed);
    cout << "Enter 4 digit seed= ";
    cin >> spins;
    for (i=0;i<spins;i++) brand();
    pp[0]=2;
    do
    {  /* find prime p = 2.pp[1].pp[2]....+1 */
        p=2;
        for (i=1;i<NPRIMES-1;i++)
        { /* generate all but last prime */
            q=rand(i+6,10);
            pp[i]=nextprime(q);
            p*=pp[i];
        }
        do
        { /* find last prime component such that p is prime */
            q=nextprime(q);
            pp[NPRIMES-1]=q;
            t=p*pp[NPRIMES-1];
            t+=1;
        } while(!prime(t));
        p=t;
        found=TRUE;
        for (i=0;i<NPRIMES;i++)
        { /* check that PROOT is a primitive root */
            if (pow(PROOT,(p-1)/pp[i],p)==1) 
            {
                found=FALSE;
                break;
            }
        }
    } while (!found);
    prime_data << NPRIMES << "\n";
    for (i=0;i<NPRIMES;i++) prime_data << pp[i] << endl;
    cout << "prime= \n" << p;
    return 0;
}
Пример #13
0
int ShoeDescription::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 1)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 1;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< int*>(_v) = size(); break;
        case 1: *reinterpret_cast< QColor*>(_v) = color(); break;
        case 2: *reinterpret_cast< QString*>(_v) = brand(); break;
        case 3: *reinterpret_cast< qreal*>(_v) = price(); break;
        }
        _id -= 4;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setSize(*reinterpret_cast< int*>(_v)); break;
        case 1: setColor(*reinterpret_cast< QColor*>(_v)); break;
        case 2: setBrand(*reinterpret_cast< QString*>(_v)); break;
        case 3: setPrice(*reinterpret_cast< qreal*>(_v)); break;
        }
        _id -= 4;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 4;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 4;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 4;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 4;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 4;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 4;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Пример #14
0
void irand(_MIPD_ mr_unsign32 seed)
{ /* initialise random number system */
    int i,in;
    mr_unsign32 t,m=1L;
#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif
    mr_mip->borrow=0L;
    mr_mip->rndptr=0;
    mr_mip->ira[0]^=seed;
    for (i=1;i<NK;i++)
    { /* fill initialisation vector */
        in=(NV*i)%NK;
        mr_mip->ira[in]=m; 
        t=m;
        m=seed-m;
        seed=t;
    }
    for (i=0;i<1000;i++) brand(_MIPPO_ ); /* "warm-up" & stir the generator */
}
    /// Random offset for given transform.
    ///
    /// \param transform Tranform to interpolate from.
    /// \param center Object center.
    /// \param seed Seed for random numbers.
    /// \param interp Interpolation value.
    /// \return Transform interpolated towards random offset.
    static mat4 randomOffsetTransform(const mat4 &transform, const vec3& center, unsigned seed, float interp)
    {
      static const float HIGH_DIFF = 12.0f;
      static const float MID_DIFF = 8.0f;
      static const float LOW_DIFF = 4.0f;
      static const float MIN_SCALE = 0.01f;
      mat4 ret(MIN_SCALE, 0.0f, 0.0f, 0.0f,
          0.0f, MIN_SCALE, 0.0f, 0.0f,
          0.0f, 0.0f, MIN_SCALE, 0.0f,
          0.0f, 0.0f, 0.0f, 1.0f);

      bsd_srand(seed);

      float diff_x = frand(MID_DIFF, HIGH_DIFF);
      float diff_y = frand(LOW_DIFF, HIGH_DIFF);
      float diff_z = frand(LOW_DIFF, HIGH_DIFF);

      ret[12] = randomOffsetCoord(center[0], diff_x);
      ret[13] = randomOffsetCoord(center[1], diff_y);
      ret[14] = center[2] + (brand(-1.0f, 1.0f) * diff_z);

      return mix(ret, transform, interp);
    }
Пример #16
0
int main (int argc, char *argv[])
{
   static char cvs_info[] = "BMkGRP $Date: $ $Revision: $ $RCSfile: all2all_main.c,v $ $Name: $";

   int itr;
   int idx;
   brand_t br;
   timer t, t0, t1;
   double nsec;

   double total_time = 0.0;
  
   int status = 0;
  
   int64 i, seed, arg, msize, tsize, len, oldsize=0, rep, cksum;
   uint64 *tab=NULL;
  
   start_pes(0);
   SELF=_my_pe();
   SIZE=_n_pes();

   if (argc < 5) {
      if (SELF == 0)
         fprintf (stderr, "Usage:\t%s seed msg_size(B) table_size(MB) rep_cnt "
	          "[ms2 ts2 rc2 ..]\n", argv[0]);
         status = 1;
      goto DONE;
   }
   seed = atol (argv[1]);
   if (SELF == 0)
      printf ("base seed is %ld\n", seed);
   seed += SELF << 32;
   brand_init (&br, seed);  // seed uniquely per PE

   arg = 2;
  
   while (arg < argc) {
    
    
      msize = atol (argv[arg++]);               if (arg >= argc)  break;
      /* Table size * 1 million. */
      tsize = atol (argv[arg++]) * (1L << 20);  if (arg >= argc)  break;
      //rep   = atol (argv[arg++]);
      rep   = 1;
      arg++;

      if (SELF == 0)  printf ("tsize = %ldMB  msize = %dB\n",
			        tsize/(1L<<20), msize);
      if (msize < sizeof(long)) {
         if (SELF == 0)  printf ("msize too short!\n");
         //status = 1;
         goto DONE;
      }
      //itr=0;

      idx = 0;

      switch(SIZE){
         case 2:
            idx = 0;
            break;
         case 4:
            idx = 1;
            break;
         case 8:
            idx = 2;
            break;
         default:
            fprintf(stderr,"warning, check sum for (%d) pes not supported.\n",
                        SIZE);
      }
 
      while (rep-- > 0) {

         /* START TIMING */
         //timer_clear (&t0);
         //timer_clear (&t1);
         //timer_start (&t0);
	    
         if ((tab == NULL) || (tsize > oldsize)) {
	   if (tab != NULL) {
	      dram_shfree (tab);
	      oldsize = 0;
	   }
	   if (SELF == 0)  printf ("trying dram_shmalloc of %ld bytes\n", tsize);
	   tab = (uint64 *) dram_shmalloc (tsize);
	
	   if (tab == NULL) {
	      if (SELF == 0)  printf ("dram_shmalloc failed!\n");
               status = 1;
	      goto DONE;
	  
	   }
	   oldsize = tsize;
         }
      
         // length in words
         len = tsize / sizeof(uint64);
      
         // important to init table
         // to ensure cksum consistency on different platforms
         memset(tab,0,tsize);
      
         for (i = 0; i < len; i+=64){
            tab[i] = brand(&br);
         }
     
         // we'll have destination/source arrays each of half size
         len /= 2;

         //timer_stop (&t0);
         // source checksum
         cksum = do_cksum (&tab[len], len);
         if (SELF == 0)  printf ("cksum is %016lx\n", cksum);
         if (SELF == 0){
            //if(cksum!=ckv[itr++]){
            /* Set up for one iteration only. */
            if(cksum!=ckv[idx]){
               printf ("cksum  %016lx != ckv[%d] %016x\n",cksum,idx,ckv[idx]);
	         gexit(1);
	   }
          
         }      	      

         //timer_start (&t1);
         len = do_all2all (&tab[0], &tab[len], len, msize/sizeof(uint64));
      
         shmem_barrier_all();
      
         //timer_stop (&t1);
         /* END TIMING */
#if 0

         // dest checksum
         i = do_cksum (&tab[0], len);
         if (i != cksum) {
	   printf ("PE %4ld  ERROR: %016lx != %016lx\n", SIZE, i, cksum);
	   status = 1;
	   goto DONE;
         }

#ifndef CHECKOFF
         if (i != known_v[gv]) {
            printf ("CHECKSUM PE %4ld  ERROR: %016lx != %016lx\n", SIZE, i, known_v[gv]);
            status = 1;
            goto DONE;
         }
         gv++;
#endif


         //t.accum_wall = t0.accum_wall + t1.accum_wall;
         //t.accum_cpus = t0.accum_cpus + t1.accum_cpus;


         /*if (SELF == 0) {

#ifdef PTIMES
	   printf ("%8.3f %8.3f\n",    t0.accum_wall , t1.accum_wall);
	   printf ("%8.3f %8.3f\n",    t0.accum_cpus , t1.accum_cpus);
#endif
	   printf ("wall reports %8.3f secs  cpus report %8.3f secs\n",
		    t.accum_wall, t.accum_cpus);
	   nsec = MAX(t.accum_wall, t.accum_cpus);
            total_time += nsec;
	   if (nsec > 0)
	     printf ("%8.3f MB/sec with %ld bytes transfers\n",
		     len*sizeof(uint64)/(double)(1L<<20)/nsec, msize);
         }*/
#endif
      }
      //if (SELF == 0)
         //printf ("\n");
   }
   //if (SELF == 0)
   //{
      //printf ("total time = %14.9f\n", total_time);

   //}
 
 DONE: 
   shmem_barrier_all();
   return status;
}
Пример #17
0
void do_bcast  (TYPE *dst, TYPE *src, int64 nwrds, brand_t *br, int64 msize,
		int64 rep, int64 fix_root)

{
  timer t;
  int64 i, n, root, max;
  uint64 x, cksum;
  uint64 *ldst, *lsrc;

  do_sync_init();

  // set pointers to local data
#if defined(__UPC__)
  ldst = (uint64 *)&dst[MY_GTHREAD];
  lsrc = (uint64 *)&src[MY_GTHREAD];
  
#else
  ldst = &dst[0];
  lsrc = &src[0];

#endif

  // touch all memory
  bzero ((void *)&ldst[0], nwrds * sizeof(uint64));
  bzero ((void *)&lsrc[0], nwrds * sizeof(uint64));
  
  // doing reps of powers-of-2 wrds up to max
  max = msize / sizeof(uint64);
  for (n = 1; n < (2 * max); n *= 2)
    {
      if (n > max)
	n = max;

      // fill src buff w/ data
      for (i = 1; i < n; i++) {
	x = brand(br) ^ val;
	lsrc[i] = x;
      }

      // Start Timing
      timer_clear (&t);
      timer_start (&t);
      for (i = 0; i < rep; i++) {
	// used fixed root if specified
	root = fix_root;
	if (root < 0)
	  root = brand(br) % GTHREADS;
	lsrc[0] = brand(br) ^ val;

	// broadcast n wrds from root to all PEs
	mpp_broadcast (dst, src, n, root);
      }
      mpp_barrier_all();
      timer_stop (&t);

      //
      // verify checksum on last iter
      //

      // compute global checksum
      x = 0;
      for (i = 0; i < n; i++)
	x += ldst[i];
      cksum = mpp_accum_long (x);
      // compare to local (should be x*GTHREADS)
      if ((GTHREADS * x) != cksum) {
	printf ("ERROR: expected bcast cksum %016lx (got %016lx)\n", 
		GTHREADS * x, cksum);
	mpp_exit(1);
      }
      mpp_barrier_all();

      if (MY_GTHREAD == 0) {
	//printf ("root %ld cksum is %016lx\n", root, cksum);
	print_results (n, rep, t.accum_wall);
      }
    }

  if (MY_GTHREAD == 0)
    printf ("cksum is %016lx\n", cksum);
}
Пример #18
0
int main (int argc, char *argv[])

{
  brand_t br;
  int64 i, seed, msize, niters, root = -1;
  const int64 nwrds = NWRDS / 2;
  double mem;
  char *scale;
  TYPE *dst, *src;

  start_pes(0);
  //mpp_init();
  open_df_mmu();

  if (argc < 4) {
    if (MY_GTHREAD == 0)
      fprintf (stderr, "Usage:\t%s seed msize(B) niters [root]\n", argv[0]);
    goto DONE;
  }

  // alloc two shared buffers
  // (mpp_alloc checks for valid pointer and casts)
  dst = mpp_alloc (nwrds * sizeof(uint64)); 
  src = mpp_alloc (nwrds * sizeof(uint64)); 

  // get args
  seed = atol (argv[1]);
  msize = atol (argv[2]);
  niters = atol (argv[3]);
  if (argc > 4)
    root = atol (argv[4]);

  // seed uniquely to generate a unique val /PE
  brand_init (&br, seed + ((int64)MY_GTHREAD << 32));
  val = brand(&br);
  // seed uniformly across PEs for benchmark
  brand_init (&br, seed);
  // runup a few times
  for (i = 0; i < 8; i++)  brand(&br);

  if (MY_GTHREAD == 0) {
    printf ("base seed is %ld\n", seed);
    mem = scale_mem (msize, &scale);
    printf ("msize = %.2lf %s\n", mem, scale);
  }
  if (msize < sizeof(uint64)) {
    if (MY_GTHREAD == 0)
      printf ("msize must be > %ld B\n", (int64)sizeof(uint64));
    goto DONE;
  }
  if (msize > (nwrds * sizeof(uint64))) {
    if (MY_GTHREAD == 0)
      printf ("msize must be < %ld B\n", nwrds * sizeof(uint64));
    goto DONE;
  }
  if (root >= GTHREADS)
    root = -1;
  if (MY_GTHREAD == 0) {
    if (root < 0)
      printf ("randomizing root PEs (%ld)\n", root);
    else
      printf ("using fixed root PE %ld\n", root);
  }

  // this exits on error
  do_bcast (dst, src, nwrds, &br, msize, niters, root);
  
  // free up the shared memory
  mpp_free (dst);
  mpp_free (src);

 DONE:
  mpp_barrier_all();
  //mpp_finalize();
  close_df_mmu();
  return 0;
}
Пример #19
0
int CALLBACK WinMain(
    HINSTANCE   hInstance,
    HINSTANCE   hPrevInstance,
    LPSTR       lpCmdLine,
    int         nCmdShow)
{
    s_gameFuncs = LoadGameFuncs();
    assert(s_gameFuncs.valid);

    ImGuiIO& io = ImGui::GetIO();
    //io.MemAllocFn = memory::malloc;
    //io.MemFreeFn = memory::free;

    //_crtBreakAlloc = 4015;
    s_queue = new util::ThreadSafeQueue<WindowEvent>();

    g_LogInfo(SL_BUILD_DATE);

    // Log CPU features
    {
#if 0
        struct CPUInfo {
            union {
                int i[4];
            };
        } info = { 0 };

        // Get number of functions
        __cpuid(info.i, 0);
        int nIds_ = info.i[0];

        // Dump info
        std::vector<CPUInfo> data;
        for (int i = 0; i <= nIds_; ++i)
        {
            __cpuidex(info.i, i, 0);
            data.push_back(info);
        }

        // Vendor
        if(data.size() >= 0) {
            char vendor[13] = {0};
            memcpy(vendor + 0, data[0].i + 1, 4);
            memcpy(vendor + 4, data[0].i + 3, 4);
            memcpy(vendor + 8, data[0].i + 2, 4);
            g_LogInfo("CPU Vendor: " + std::string(vendor));
        }
#endif
        // http://stackoverflow.com/questions/850774/how-to-determine-the-hardware-cpu-and-ram-on-a-machine
        int CPUInfo[4] = { 0 };
        char CPUBrandString[0x40];
        // Get the information associated with each extended ID.
        __cpuid(CPUInfo, 0x80000000);
        int nExIds = CPUInfo[0];
        for (int i = 0x80000000; i <= nExIds; i++)
        {
            __cpuid(CPUInfo, i);
            // Interpret CPU brand string
            if  (i == 0x80000002)
                memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
            else if  (i == 0x80000003)
                memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo));
            else if  (i == 0x80000004)
                memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
        }
        //string includes manufacturer, model and clockspeed
        std::string brand(CPUBrandString);
        g_LogInfo(brand.substr(brand.find_first_not_of(" ")));

        SYSTEM_INFO sysInfo;
        GetSystemInfo(&sysInfo);
        g_LogInfo("Logical processors: " + std::to_string(sysInfo.dwNumberOfProcessors));

        MEMORYSTATUSEX statex;
        statex.dwLength = sizeof (statex);
        GlobalMemoryStatusEx(&statex);
        g_LogInfo("Total System Memory: " + std::to_string(statex.ullTotalPhys/1024/1024) + " MB");
    }

    auto className = L"StarlightClassName";

    WNDCLASSEXW wndClass = { 0 };
    wndClass.cbSize = sizeof(WNDCLASSEXW);
    wndClass.style = CS_CLASSDC;
    wndClass.lpfnWndProc = WndProc;
    wndClass.hInstance = GetModuleHandleW(nullptr);
    wndClass.hCursor = LoadCursorW(nullptr, IDC_ARROW);
    wndClass.lpszClassName = className;

    RegisterClassExW(&wndClass);

    // Get desktop rectangle
    RECT desktopRect;
    GetClientRect(GetDesktopWindow(), &desktopRect);

    // Get window rectangle
    RECT windowRect = { 0, 0, 800, 600 }; // TODO: Config file?
    AdjustWindowRect(&windowRect, WS_OVERLAPPEDWINDOW, FALSE);

    // Calculate window dimensions
    LONG windowWidth = windowRect.right - windowRect.left;
    LONG windowHeight = windowRect.bottom - windowRect.top;
    LONG x = desktopRect.right / 2 - windowWidth / 2;
    LONG y = desktopRect.bottom / 2 - windowHeight / 2;

#ifdef _DEBUG
    // Move the screen to the right monitor on JOTARO
    wchar_t computerName[MAX_COMPUTERNAME_LENGTH + 1];
    DWORD dwSize = sizeof(computerName);
    GetComputerNameW(computerName, &dwSize);
    if (wcscmp(computerName, L"JOTARO") == 0) {
        x += 1920;
    }
#endif

    s_config.Load();

    s_hwnd = CreateWindowExW(
        0L,
        className,
        L"Starlight",
        WS_OVERLAPPEDWINDOW,
        x,
        y,
        windowWidth,
        windowHeight,
        nullptr,
        nullptr,
        GetModuleHandleW(nullptr),
        nullptr
        );

    // Show the window
    ShowWindow(s_hwnd, SW_MAXIMIZE);
    UpdateWindow(s_hwnd);

    // Create thread
    s_running.store(true);
    unsigned int threadID;
    HANDLE thread = (HANDLE) _beginthreadex(nullptr, 0, MyThreadFunction, nullptr, 0, &threadID);
    if (!thread) {
        // Error creating thread
        return 1;
    }

    // Watch Lua directory
    hDirectoryChange = FindFirstChangeNotification(L"../starlight/", TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE);
    if (!hDirectoryChange) {
        g_LogInfo("Error creating directory change notification handle: Lua reload on save will not work.");
    }

    // Message loop
    MSG msg;
    while (s_running.load() && GetMessageW(&msg, nullptr, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessageW(&msg);
    }

    WaitForSingleObject(thread, INFINITE);
    CloseHandle(thread);

    if (hDirectoryChange) {
        if (!FindCloseChangeNotification(hDirectoryChange)) {
            g_LogInfo("Failed to close directory change notification handle.");
        }
    }

    s_gameFuncs.DestroyLogger();

    io.Fonts->Clear();

    s_config.Save();

    delete s_queue;

    UnregisterClassW(className, GetModuleHandleW(nullptr));

    _CrtDumpMemoryLeaks();

    return 0;
}
Пример #20
0
/**
 * \brief Creates and initializes the working data for the plan
 * \param [in] plan The struct that holds the plan's data values.
 * \return int Error flag value
 * \sa parseCBAPlan
 * \sa makeCBAPlan
 * \sa execCBAPlan
 * \sa perfCBAPlan
 * \sa killCBAPlan
 */
int initCBAPlan(void *plan){
    int ret = make_error(ALLOC,generic_err);
    int i;
    int nrow, ncol;
    Plan *p;
    CBA_data *ci = NULL;
    p = (Plan *)plan;

    #ifdef HAVE_PAPI
    int temp_event, k;
    int PAPI_Events [NUM_PAPI_EVENTS] = PAPI_COUNTERS;
    char *PAPI_units [NUM_PAPI_EVENTS] = PAPI_UNITS;
    #endif //HAVE_PAPI

    if(p){
        ci = (CBA_data *)p->vptr;
        p->exec_count = 0;
        if(DO_PERF){
            perftimer_init(&p->timers, NUM_TIMERS);

            #ifdef HAVE_PAPI
            /* Initialize plan's PAPI data */
            p->PAPI_EventSet = PAPI_NULL;
            p->PAPI_Num_Events = 0;

            TEST_PAPI(PAPI_create_eventset(&p->PAPI_EventSet), PAPI_OK, MyRank, 9999, PRINT_SOME);

            //Add the desired events to the Event Set; ensure the dsired counters
            //  are on the system then add, ignore otherwise
            for(k = 0; k < TOTAL_PAPI_EVENTS && k < NUM_PAPI_EVENTS; k++){
                temp_event = PAPI_Events[k];
                if(PAPI_query_event(temp_event) == PAPI_OK){
                    p->PAPI_Num_Events++;
                    TEST_PAPI(PAPI_add_event(p->PAPI_EventSet, temp_event), PAPI_OK, MyRank, 9999, PRINT_SOME);
                }
            }

            PAPIRes_init(p->PAPI_Results, p->PAPI_Times);
            PAPI_set_units(p->name, PAPI_units, NUM_PAPI_EVENTS);

            TEST_PAPI(PAPI_start(p->PAPI_EventSet), PAPI_OK, MyRank, 9999, PRINT_SOME);
            #endif //HAVE_PAPI
        }         //DO_PERF
    }
    if(ci){
        brand_init(&(ci->br), ci->seed);

        nrow = ci->nrows;
        ncol = ci->ncols;

        ci->niter *= 64;          /* we'll do iterations in blocks of 64 */

        if((ci->ncols % BLOCKSIZE) != 0){
            return make_error(0,specific_err);
            //fprintf(stderr, "ERROR (plan_cba): BLOCKSIZE (%ld) must divide"
            //" ncol (%ld)\n", BLOCKSIZE, ncol);
        }
        assert ((NITERS % 64) == 0);

        ci->work = (uint64_t *)calloc((size_t)((nrow * ncol + PAD + NITERS) * 2),
                                      sizeof(uint64_t));
        ret = (ci->work == NULL) ? make_error(ALLOC,generic_err) : ERR_CLEAN;

        ci->out = &(ci->work[nrow * ncol + PAD]);
        ci->data = &(ci->out[NITERS]);
        ci->chk = &(ci->data[nrow * ncol + PAD]);

        for(i = 0; i < (nrow * ncol); i++){
            ci->data[i] = brand(&(ci->br));
        }

        blockit (ci->data, nrow, ncol, ci->work);
    }
    return ret;
} /* initCBAPlan */