Esempio n. 1
0
File: permute.c Progetto: YIwama/bcb
long *
permute_dist(distribution *d, long stream)
	{
	static distribution *dist = NULL;
	int i;
	
	if (d != NULL)
		{
		if (d->permute == (long *)NULL)
			{
			d->permute = (long *)malloc(sizeof(long) * (DIST_SIZE(d)));
			MALLOC_CHECK(d->permute);
			for (i=0; i < (DIST_SIZE(d)); i++) 
				*(d->permute + i) = i;
			}
		dist = d;
		return(permute(dist->permute, DIST_SIZE(dist), stream));
		}
	
	
	if (dist != NULL)
		return(permute(NULL, DIST_SIZE(dist), stream));
	else
		INTERNAL_ERROR("Bad call to permute_dist");	
	}
Esempio n. 2
0
long *
permute_dist(distribution *d, long stream, 
             DSS_HUGE& source, distribution* cd)
{
  static bool bInit = false;
  static distribution *dist = NULL;
	
  if (d != NULL) {
    if (d->permute == (long *)NULL) {
      d->permute = (long *)malloc(sizeof(long) * DIST_SIZE(d));
      MALLOC_CHECK(d->permute);
      //IP: permute does the same 
      //for (int i=0; i < DIST_SIZE(d); i++) {
      //   *(d->permute + i) = i;
      //}
    }

    while (!bInit) {
      dist = d;
      bInit = true;
    }
    // IP: This will not work in general, but afaict from the code
    //     this function (permute_dist) is called only by mk_part
    //     so 'dist' will never have to change its value. 
    //     This assertion ensures that 'dist' will have a single 
    //     value.    
    assert (dist == d);
    return (permute(dist->permute, DIST_SIZE(dist), stream, 
                    source, cd->permute));
  }
		
  if (dist != NULL) {
    return (permute(NULL, DIST_SIZE(dist), stream, source, cd->permute));
  }
  else {
    INTERNAL_ERROR("Bad call to permute_dist");	
  }

  return (NULL);
}