Пример #1
0
int main(void)
{
    byte* buffer;
    byte* pivots;
    size_t i;

    comb_init();  
    buffer = malloc(NUM_COMBS_ITER * COMB_SIZE);
    pivots = malloc(NUM_FILES * COMB_SIZE);

    for (i = 0; i < NUM_ITERS; i++)
    {
        printf("\nIteration %d of %d.\n\n", i + 1, NUM_ITERS);

        printf("Filling combinations buffer...");
        timer_reset();
        fill_comb_buffer(buffer);
        printf(" DONE in %fs.\n", timer_elapsed());

        printf("Sorting combinations buffer...");
        timer_reset();
        qsort(buffer, NUM_COMBS_ITER, COMB_SIZE, comb_sum_cmp);
        printf(" DONE in %fs.\n", timer_elapsed());

        if (i == 0)
        {
            printf("Creating output files...");
            create_output_files();
            printf(" DONE.\n");

            printf("Getting and saving pivots...");
            get_pivots(pivots, buffer);
            save_pivots(pivots);
            printf(" DONE.\n");
        }

        printf("Saving sorted combinations buffer...");
        timer_reset();
        save_comb_buffer(buffer, pivots);
        printf(" DONE in %fs.\n", timer_elapsed());
    }

    free(buffer);
    free(pivots);
    comb_free();

    return 0;
}
Пример #2
0
/**
   Create combination of stars to form asterism. It has the option to put TTF
   always on the brightest for testing purpose.  */
ASTER_S *setup_aster_comb(int *naster, int nstar, const PARMS_S *parms){
    if(nstar==0){
	*naster=0;
	return NULL;
    }else if(parms->skyc.keeporder){
	/*Use the same order as input stars.*/
	ASTER_S *aster=calloc(1, sizeof(ASTER_S));
	*naster=1;
	int npowfs=parms->maos.npowfs;
	int nleft=nstar;
	int stars[npowfs];
	for(int ipowfs=0; ipowfs<npowfs; ipowfs++){
	    stars[ipowfs]=MIN(nleft, parms->skyc.nwfsmax[ipowfs]);
	    nleft-=stars[ipowfs];
	}
	if(nleft>0){
	    warning("skyc.keeporder is set, but there are more stars than needed, dropped the extra\n");
	}
	int ntot=nstar-nleft;
	aster[0].nwfs=ntot;
	aster[0].wfs=calloc(ntot, sizeof(WFS_S));
	aster[0].iaster=0;
	int count=0;
	for(int ipowfs=0; ipowfs<npowfs; ipowfs++){
	    for(int istar=0; istar<stars[ipowfs]; istar++){
		aster[0].wfs[count].ipowfs=ipowfs;
		aster[0].wfs[count].istar=count;
		count++;
	    }
	}
	return aster;
    }
    
    int ncomb=1;
    ASTER_S *aster;
    int npowfs=parms->skyc.npowfs;
    int nwfs[npowfs];
    int nleft;
    int nwfstot=0;
    nleft=nstar;
    for(int ipowfs=0; ipowfs<npowfs; ipowfs++){
	if(nleft>=parms->skyc.nwfsmax[ipowfs]){
	    nwfs[ipowfs]=parms->skyc.nwfsmax[ipowfs];
	}else{
	    nwfs[ipowfs]=nleft;
	}
	nwfstot+=nwfs[ipowfs];
	ncomb*=comb_select(nleft,nwfs[ipowfs]);
	nleft-=nwfs[ipowfs];
    }
    if(parms->skyc.ttfbrightest){
	if(parms->maos.msa[0]==2){
	    ncomb/=comb_select(nwfstot,nwfs[0]);
	}else{
	    error("Please revise\n");
	}
    }
    if(parms->skyc.verbose){
	info2("Number of stars: %d, number of asterisms: %d\n", nstar, ncomb);
    }
    aster=calloc(ncomb, sizeof(ASTER_S));
    int count=0;
    int *comb=comb_init(nwfstot);
    do{
	if(npowfs==1){
	    aster[count].nwfs=nwfs[0];
	    aster[count].wfs=calloc(nwfs[0], sizeof(WFS_S));
	    aster[count].iaster=count;
	    for(int iwfs=0; iwfs<nwfs[0]; iwfs++){
		aster[count].wfs[iwfs].istar=comb[iwfs];
		aster[count].wfs[iwfs].ipowfs=0;
	    }
	    count++;
	}else if(npowfs==2){
	    int mask[nwfstot];
	    int *comb2=comb_init(nwfs[0]);
	    do{
		memset(mask, 0, sizeof(int)*nwfstot);
		aster[count].nwfs=nwfstot;
		aster[count].wfs=calloc(nwfstot, sizeof(WFS_S));
		aster[count].iaster=count;
		for(int iwfs=0; iwfs<nwfs[0]; iwfs++){
		    aster[count].wfs[iwfs].ipowfs=0;
		    aster[count].wfs[iwfs].istar=comb[comb2[iwfs]];
		    mask[comb2[iwfs]]=1;
		}
		int jstar=0;
		for(int iwfs=0; iwfs<nwfs[1]; iwfs++){
		    aster[count].wfs[iwfs+nwfs[0]].ipowfs=1;
		    while(mask[jstar]) jstar++;
		    aster[count].wfs[iwfs+nwfs[0]].istar=comb[jstar];
		    mask[jstar]=1;
		}
		count++;
	    }while(comb_next(comb2,nwfstot,nwfs[0]) && !parms->skyc.ttfbrightest);
	    free(comb2);
	}
    }while(comb_next(comb,nstar,nwfstot));
    free(comb);
    if(count!=ncomb){
	warning("ncomb=%d, count=%d. They should equal.\n", ncomb, count);
    }
    *naster=count;
    return aster;
}
Пример #3
0
int main(void)
{
    bignum_t sum;
    int i;

    comb_init();

    timer_reset();

    for (i = 0; i < 1000; i++)
    {
        TEST_COMB_SUM("\xf3\xe7\x7f\xfe\x9f\xff\xbd\xff\x37");
        TEST_COMB_SUM("\xad\xbd\xde\xff\xfb\xff\xbb\xf7\x2d");
        TEST_COMB_SUM("\xf6\xfb\x8a\xf5\xba\xbc\x59\xb3\x0f");
        TEST_COMB_SUM("\x05\x40\x33\x02\x27\x00\x21\x87\x1e");
        TEST_COMB_SUM("\x04\x00\x81\x06\x90\x08\x00\x52\x0c");
        TEST_COMB_SUM("\x10\x0c\x08\x90\xba\x80\x12\x0b\x02");
        TEST_COMB_SUM("\xf1\xd0\xa1\x42\x82\x89\x31\x51\x3a");
        TEST_COMB_SUM("\x00\x00\x00\x00\x80\x80\x00\x00\x00");
        TEST_COMB_SUM("\xbf\xff\xff\xff\xff\xf5\xff\xff\x3f");
        TEST_COMB_SUM("\x94\x15\x90\x31\x00\x22\x40\x07\x20");
        TEST_COMB_SUM("\xaf\x1f\x0c\xa4\x54\x76\xca\xef\x16");
        TEST_COMB_SUM("\x00\x00\x00\x00\x26\x68\x04\x10\x14");
        TEST_COMB_SUM("\xbf\xf7\x1b\xdf\xd7\xb7\x5e\xff\x1a");
        TEST_COMB_SUM("\x0c\x05\xc0\xb1\x82\x7f\x9b\x9e\x1b");
        TEST_COMB_SUM("\xfb\x1b\x3b\xbf\x7c\xef\xff\x7f\x3b");
        TEST_COMB_SUM("\x06\x01\x25\x04\x00\x00\x42\x40\x02");
        TEST_COMB_SUM("\x20\x02\x00\x20\x40\x00\x08\x00\x00");
        TEST_COMB_SUM("\x68\x98\x5a\x4d\x30\xb6\x42\xd0\x2a");
        TEST_COMB_SUM("\x57\xfa\x8c\xca\xa2\xae\x13\x45\x14");
        TEST_COMB_SUM("\x40\x05\x9f\x99\x7b\x10\x00\xc1\x20");
    }

    printf("Elapsed time: %fs\n", timer_elapsed());

    timer_reset();

    for (i = 0; i < 1000; i++)
    {
        TEST_COMB_FSUM("\xf3\xe7\x7f\xfe\x9f\xff\xbd\xff\x37");
        TEST_COMB_FSUM("\xad\xbd\xde\xff\xfb\xff\xbb\xf7\x2d");
        TEST_COMB_FSUM("\xf6\xfb\x8a\xf5\xba\xbc\x59\xb3\x0f");
        TEST_COMB_FSUM("\x05\x40\x33\x02\x27\x00\x21\x87\x1e");
        TEST_COMB_FSUM("\x04\x00\x81\x06\x90\x08\x00\x52\x0c");
        TEST_COMB_FSUM("\x10\x0c\x08\x90\xba\x80\x12\x0b\x02");
        TEST_COMB_FSUM("\xf1\xd0\xa1\x42\x82\x89\x31\x51\x3a");
        TEST_COMB_FSUM("\x00\x00\x00\x00\x80\x80\x00\x00\x00");
        TEST_COMB_FSUM("\xbf\xff\xff\xff\xff\xf5\xff\xff\x3f");
        TEST_COMB_FSUM("\x94\x15\x90\x31\x00\x22\x40\x07\x20");
        TEST_COMB_FSUM("\xaf\x1f\x0c\xa4\x54\x76\xca\xef\x16");
        TEST_COMB_FSUM("\x00\x00\x00\x00\x26\x68\x04\x10\x14");
        TEST_COMB_FSUM("\xbf\xf7\x1b\xdf\xd7\xb7\x5e\xff\x1a");
        TEST_COMB_FSUM("\x0c\x05\xc0\xb1\x82\x7f\x9b\x9e\x1b");
        TEST_COMB_FSUM("\xfb\x1b\x3b\xbf\x7c\xef\xff\x7f\x3b");
        TEST_COMB_FSUM("\x06\x01\x25\x04\x00\x00\x42\x40\x02");
        TEST_COMB_FSUM("\x20\x02\x00\x20\x40\x00\x08\x00\x00");
        TEST_COMB_FSUM("\x68\x98\x5a\x4d\x30\xb6\x42\xd0\x2a");
        TEST_COMB_FSUM("\x57\xfa\x8c\xca\xa2\xae\x13\x45\x14");
        TEST_COMB_FSUM("\x40\x05\x9f\x99\x7b\x10\x00\xc1\x20");
    }

    printf("Elapsed time: %fs\n", timer_elapsed());

    timer_reset();

    for (i = 0; i < 1000000; i++)
    {
        byte comb[12];
        ((uint32_t*)comb)[0] = get_random();
        ((uint32_t*)comb)[1] = get_random();
        ((uint32_t*)comb)[2] = get_random() & ((1 << (70 - 64)) - 1);

        comb_sum(&sum, comb);
    }

    printf("Elapsed time: %fs\n", timer_elapsed());

    timer_reset();

    for (i = 0; i < 1000000; i++)
    {
        byte comb[12];
        ((uint32_t*)comb)[0] = get_random();
        ((uint32_t*)comb)[1] = get_random();
        ((uint32_t*)comb)[2] = get_random() & ((1 << (70 - 64)) - 1);

        comb_fast_sum(&sum, comb);
    }

    printf("Elapsed time: %fs\n", timer_elapsed());

    bignum_print(&sum);

    comb_free();

    return 0;
}
Пример #4
0
int main(void)
{
    TEST_COMB_SUM("\x03\x00\xf0\x00\x00\x00\x00\x00\x01",
                  "0x00000002c45568047b7b14d2");
    TEST_COMB_SUM("\xf3\xe7\x7f\xfe\x9f\xff\xbd\xff\x37",
                  "0x000000132d3993b60360b828");
    TEST_COMB_SUM("\xad\xbd\xde\xff\xfb\xff\xbb\xf7\x2d",
                  "0x0000001250634400f9c20229");
    TEST_COMB_SUM("\xf6\xfb\x8a\xf5\xba\xbc\x59\xb3\x0f",
                  "0x0000000e897a48b08371a7de");
    TEST_COMB_SUM("\x05\x40\x33\x02\x27\x00\x21\x87\x1e",
                  "0x00000007df49486f4ff7735c");
    TEST_COMB_SUM("\x04\x00\x81\x06\x90\x08\x00\x52\x0c",
                  "0x00000004e34cac705377aa57");
    TEST_COMB_SUM("\x10\x0c\x08\x90\xba\x80\x12\x0b\x02",
                  "0x00000005727d4a458d556615");
    TEST_COMB_SUM("\xf1\xd0\xa1\x42\x82\x89\x31\x51\x3a",
                  "0x000000087df3a1c78b4fba98");
    TEST_COMB_SUM("\x00\x00\x00\x00\x80\x80\x00\x00\x00",
                  "0x00000000a3b1d700e11c4dc7");
    TEST_COMB_SUM("\xbf\xff\xff\xff\xff\xf5\xff\xff\x3f",
                  "0x00000015b888c83418072182");
    TEST_COMB_SUM("\x94\x15\x90\x31\x00\x22\x40\x07\x20",
                  "0x000000063630a50b6b799b3e");
    TEST_COMB_SUM("\xaf\x1f\x0c\xa4\x54\x76\xca\xef\x16",
                  "0x0000000c02cf5161ef17427e");
    TEST_COMB_SUM("\x00\x00\x00\x00\x26\x68\x04\x10\x14",
                  "0x00000003064a3398e6ef1705");
    TEST_COMB_SUM("\xbf\xf7\x1b\xdf\xd7\xb7\x5e\xff\x1a",
                  "0x000000109146ee1decac1702");
    TEST_COMB_SUM("\x0c\x05\xc0\xb1\x82\x7f\x9b\x9e\x1b",
                  "0x0000000aa2e4848e3fe98ac1");
    TEST_COMB_SUM("\xfb\x1b\x3b\xbf\x7c\xef\xff\x7f\x3b",
                  "0x000000110e99540998db17e9");
    TEST_COMB_SUM("\x06\x01\x25\x04\x00\x00\x42\x40\x02",
                  "0x000000041583f02b89c5d14e");
    TEST_COMB_SUM("\x20\x02\x00\x20\x40\x00\x08\x00\x00",
                  "0x00000001b091f915fac6d8e7");
    TEST_COMB_SUM("\x68\x98\x5a\x4d\x30\xb6\x42\xd0\x2a",
                  "0x0000000930c74d0b12740c95");
    TEST_COMB_SUM("\x57\xfa\x8c\xca\xa2\xae\x13\x45\x14",
                  "0x0000000a953673128d09ec0b");
    TEST_COMB_SUM("\x40\x05\x9f\x99\x7b\x10\x00\xc1\x20",
                  "0x000000083495cdffd2a15a89");

    comb_init();

    TEST_COMB_FSUM("\x03\x00\xf0\x00\x00\x00\x00\x00\x01",
                   "0x00000002c45568047b7b14d2");
    TEST_COMB_FSUM("\xf3\xe7\x7f\xfe\x9f\xff\xbd\xff\x37",
                   "0x000000132d3993b60360b828");
    TEST_COMB_FSUM("\xad\xbd\xde\xff\xfb\xff\xbb\xf7\x2d",
                   "0x0000001250634400f9c20229");
    TEST_COMB_FSUM("\xf6\xfb\x8a\xf5\xba\xbc\x59\xb3\x0f",
                   "0x0000000e897a48b08371a7de");
    TEST_COMB_FSUM("\x05\x40\x33\x02\x27\x00\x21\x87\x1e",
                   "0x00000007df49486f4ff7735c");
    TEST_COMB_FSUM("\x04\x00\x81\x06\x90\x08\x00\x52\x0c",
                   "0x00000004e34cac705377aa57");
    TEST_COMB_FSUM("\x10\x0c\x08\x90\xba\x80\x12\x0b\x02",
                   "0x00000005727d4a458d556615");
    TEST_COMB_FSUM("\xf1\xd0\xa1\x42\x82\x89\x31\x51\x3a",
                   "0x000000087df3a1c78b4fba98");
    TEST_COMB_FSUM("\x00\x00\x00\x00\x80\x80\x00\x00\x00",
                   "0x00000000a3b1d700e11c4dc7");
    TEST_COMB_FSUM("\xbf\xff\xff\xff\xff\xf5\xff\xff\x3f",
                   "0x00000015b888c83418072182");
    TEST_COMB_FSUM("\x94\x15\x90\x31\x00\x22\x40\x07\x20",
                   "0x000000063630a50b6b799b3e");
    TEST_COMB_FSUM("\xaf\x1f\x0c\xa4\x54\x76\xca\xef\x16",
                   "0x0000000c02cf5161ef17427e");
    TEST_COMB_FSUM("\x00\x00\x00\x00\x26\x68\x04\x10\x14",
                   "0x00000003064a3398e6ef1705");
    TEST_COMB_FSUM("\xbf\xf7\x1b\xdf\xd7\xb7\x5e\xff\x1a",
                   "0x000000109146ee1decac1702");
    TEST_COMB_FSUM("\x0c\x05\xc0\xb1\x82\x7f\x9b\x9e\x1b",
                   "0x0000000aa2e4848e3fe98ac1");
    TEST_COMB_FSUM("\xfb\x1b\x3b\xbf\x7c\xef\xff\x7f\x3b",
                   "0x000000110e99540998db17e9");
    TEST_COMB_FSUM("\x06\x01\x25\x04\x00\x00\x42\x40\x02",
                   "0x000000041583f02b89c5d14e");
    TEST_COMB_FSUM("\x20\x02\x00\x20\x40\x00\x08\x00\x00",
                   "0x00000001b091f915fac6d8e7");
    TEST_COMB_FSUM("\x68\x98\x5a\x4d\x30\xb6\x42\xd0\x2a",
                   "0x0000000930c74d0b12740c95");
    TEST_COMB_FSUM("\x57\xfa\x8c\xca\xa2\xae\x13\x45\x14",
                   "0x0000000a953673128d09ec0b");
    TEST_COMB_FSUM("\x40\x05\x9f\x99\x7b\x10\x00\xc1\x20",
                   "0x000000083495cdffd2a15a89");

    comb_free();

    return 0;
}