Пример #1
0
int eaf_ks_stat(int *data, int nvars, int npoints)
{
    int i, j, k, l, maxd=0, d, cols;

    unsigned *dmap, *c, *mask;

    cols = (nvars - 1) / BPU + 1;
    dmap = calloc(npoints, cols * sizeof(unsigned));
    c = calloc(cols, sizeof(unsigned));
    mask = calloc(cols, sizeof(unsigned));

    for (j = 0; j < cols; j++)
    	for (k = 0; k < BPU && (l = j * BPU + k) < nvars/2; k++)
	    mask[j] |= (1<<k);

    for (i = 0; i < npoints; i++) {
	for (j = 0; j < cols; j++)
	    for (k = 0; k < BPU && (l = j * BPU + k) < nvars; k++)
		dmap[i * cols + j] |= (data[i * nvars + l]!=0) << k;
    }

    for (i = 0; i < npoints; i++) {
	d = 0;
	for (k = 0; k < cols; k++) {
	    c[k] = dmap[i * cols + k];
	    d += bit_weight(c[k] & mask[k]) - bit_weight(c[k] & ~mask[k]);
	}
	if (maxd < abs(d))
	    maxd = abs(d);
    }
    free(dmap);
    free(c);
    free(mask);
    return maxd;
}
Пример #2
0
int eaf2_ks_stat(int *data, int nvars, int npoints)
{
    int i, j, k, l, maxd=0, d, cols;
    const int block = 8192/2;

    unsigned *dmap, *c, *mask;

    cols = (nvars - 1) / BPU + 1;
    dmap = calloc(npoints, cols * sizeof(unsigned));
    c = calloc(cols, sizeof(unsigned));
    mask = calloc(cols, sizeof(unsigned));

    for (j = 0; j < cols; j++)
    	for (k = 0; k < BPU && (l = j * BPU + k) < nvars/2; k++)
	    mask[j] |= (1<<k);

#if 0
    printf("mask: %8x %8x\n",mask[1],mask[0]);
    printf("mask weight: %d %d\n", bit_weight(mask[1]), bit_weight(mask[0]));
#endif

    for (i = 0; i < npoints; i++) {
	for (j = 0; j < cols; j++)
	    for (k = 0; k < BPU && (l = j * BPU + k) < nvars; k++)
		dmap[i * cols + j] |= (data[i * nvars + l]!=0) << k;
/*	printf("data[%d]: %x %x\n",i, dmap[i * cols + 1], dmap[i * cols]); */
/*	printf("%d\n", bit_weight(dmap[i * cols + 1])+bit_weight(dmap[i * cols]));*/
    }

    for (l = 0; l < npoints; l += block) {
/*    printf("l = %d\n", l);*/
	for (i = l; i < npoints; i++) {
	    for (j = l; j < (l + block) && j <= i; j++) {
		d = 0;
		for (k = 0; k < cols; k++) {
		    c[k] = dmap[i * cols + k] & dmap[j * cols + k];
		    d += bit_weight(c[k] & mask[k]) - bit_weight(c[k] & ~mask[k]);
		}
		if (maxd < abs(d))
		    maxd = abs(d);
	    }
	}
    }
    free(dmap);
    free(c);
    free(mask);
    
    return maxd;
}
Пример #3
0
static void
process_smpl_buf(int id, unsigned long smpl_pmd_mask, int need_restart)
{
	static unsigned long last_overflow = ~0UL; /* initialize to biggest value possible */
	smpl_hdr_t *hdr = (smpl_hdr_t *)buf_addr;
	smpl_entry_t *ent;
	unsigned long count, entry, *reg, pos, msk;
	unsigned long entry_size;
	int j;
	


	printf("processing %s buffer at %p\n", need_restart==0 ? "leftover" : "", hdr);
	if (hdr->hdr_overflows <= last_overflow && last_overflow != ~0UL) {
		warning("skipping identical set of samples %lu <= %lu\n",
			hdr->hdr_overflows, last_overflow);
		return;	
	}
	last_overflow = hdr->hdr_overflows;

	count = hdr->hdr_count;

	ent   = (smpl_entry_t *)(hdr+1);
	pos   = (unsigned long)ent;
	entry = collect_samples;

	/*
	 * in this example program, we use fixed-size entries, therefore we
	 * can compute the entry size in advance. Perfmon-2 supports variable
	 * size entries.
	 */
	entry_size = sizeof(smpl_entry_t)+(bit_weight(smpl_pmd_mask)<<3);

	while(count--) {
		printf("entry %ld PID:%d CPU:%d IIP:0x%016lx\n",
			entry,
			ent->pid,
			ent->cpu,
			ent->ip);

		printf("\tOVFL: %d LAST_VAL: %lu\n", ent->ovfl_pmd, -ent->last_reset_val);

		/*
		 * print body: additional PMDs recorded
		 * PMD are recorded in increasing index order
		 */
		reg = (unsigned long *)(ent+1);

		for(j=0, msk = smpl_pmd_mask; msk; msk >>=1, j++) {	
			if ((msk & 0x1) == 0) continue;
			printf("PMD%-2d = 0x%016lx\n", j, *reg);
			reg++;
		}
		/*
		 * we could have removed this and used:
		 * ent = (smpl_entry_t *)reg
		 * instead.
		 */
		pos += entry_size;
		ent = (smpl_entry_t *)pos;
		entry++;
	}
	collect_samples = entry;

	/*
	 * reactivate monitoring once we are done with the samples
	 *
	 * Note that this call can fail with EBUSY in non-blocking mode
	 * as the task may have disappeared while we were processing
	 * the samples.
	 */
	if (need_restart && perfmonctl(id, PFM_RESTART, 0, 0) == -1) {
		if (errno != EBUSY)
			fatal_error("perfmonctl error PFM_RESTART errno %d\n",errno);
		else
			warning("PFM_RESTART: task has probably terminated \n");
	}
}
Пример #4
0
int *eaf2_ks_tail(int *data, int nvars, int npoints, double alpha, int nperms)
{
    int i, j, k, l;
    int n;
    int w, *D, *tail, critv, ncrit, a, d;

    unsigned *dmap, *x, *p;

#if 0  
    long long int visited = 0;
#endif
    
    const int cols = (nvars - 1) / BPU + 1;
    const int jblock = 4096	/* XBLOCK / (sizeof(unsigned) * cols)*/;

    /* assume two samples of equal size */
    if (nvars % 2) {
      fprintf(stderr,"ERROR: Sample size must be positive and even\n");
      fprintf(stderr,"       (assuming two independent samples of equal size)\n");
      return NULL;
    }

    /* number of permutations must be positive */
    if (nperms <= 0) {
      fprintf(stderr,"ERROR: Number of permutations must be positive\n");
      return NULL;      
    }

    /* Attainment data is stored in an array of bitmaps */
    dmap = calloc(npoints, cols * sizeof(unsigned));

    /* Temporary bitmap */
    x = calloc(cols, sizeof(unsigned));
    
    /* Absolute distance between EAFs per permutation */
    D = calloc(nperms, sizeof(*D));

    /* Null distribution histogram */
    tail = malloc(1+nvars/2 * sizeof(*tail));
    tail[0] = nperms;
    for (i = 1; i <= nvars/2; tail[i++] = 0);
    critv = 0;
    ncrit = 0;
    
    /* Convert significance level to no. of permutations */
    a = alpha * nperms;

    /* Create random mask */
    p = randmask(nperms, nvars, nvars/2);

    /* Store data into dmap */
    for (i = 0; i < npoints; i++) {
	for (j = 0; j < cols; j++)
	    for (k = 0; k < BPU && (l = j * BPU + k) < nvars; k++)
		dmap[i * cols + j] |= (data[i * nvars + l]!=0) << k;
    }

    for (l = 0; l < npoints; l += jblock) {
          for (i = l; i < npoints; i++) {
		for (j = l; j < (l + jblock) && j <= i; j++) {
		    w = 0;
		    for (k = 0; k < cols; k++) {
			x[k] = (dmap[i * cols + k] & dmap[j * cols + k]);
			w += bit_weight(x[k]);
		    }
		    if (w <= critv || (nvars - w) <= critv)
			continue;
#if 0
		    visited++;
#endif
		    for (n = 0; n < nperms; n++)
			if (w > D[n] && (nvars - w) > D[n]) {
			    d = 0;
			    for (k = 0; k < cols; k++)
				    d += bit_weight(x[k] & p[n*cols+k]) - bit_weight(x[k] & ~p[n*cols+k]);
			    if (D[n] < abs(d)) {
			        tail[D[n]]--;
				tail[abs(d)]++;
				if (D[n] <= critv && abs(d) > critv) {
				  ncrit++;
				  while (ncrit > a)
				    ncrit -= tail[++critv];
#if 0
                                  fprintf(stderr, "critv = %d, ncrit = %d\n", critv, ncrit);
                                  fflush(stderr);
#endif
                                }
				D[n] = abs(d);
                            }
			}
		}
          }
    }
    free(dmap);
    free(p);
    free(x);
    free(D);
    
    tail[0] = critv;
    for (i = 1; i <= critv; tail[i++]=0);

    return tail;
}