示例#1
0
文件: NBody.cpp 项目: GMAC-lib/gmac
int
NBody::verifyResults()
{
    if(verify) {
        /* reference implementation
        * it overwrites the input array with the output
        */
        refPos = (cl_float*)malloc(numBodies * sizeof(cl_float4));
        assert(refPos != NULL);
        refVel = (cl_float*)malloc(numBodies * sizeof(cl_float4));
        assert(refVel != NULL);

        memcpy(refPos, initPos, 4 * numBodies * sizeof(cl_float));
        memcpy(refVel, initVel, 4 * numBodies * sizeof(cl_float));

        for(int i = 0; i < iterations; ++i) {
            nBodyCPUReference();
        }

        /* compare the results and see if they match */
        if(!compareVector(pos, refPos, 4 * numBodies, 0.00001)) {
            exit(1);
        }
    }

    return 0;
}
示例#2
0
int main(){
		
	printf("before sorting\n");

	int i,j;

	ruleStartIndex = malloc(sizeof(int)*MAX_DIFF);

	rules = malloc(sizeof(int*)*MAX_RULES);
	
	for(i=0;i<MAX_RULES;i++){
		rules[i] = malloc(sizeof(int) * RULE_SIZE);
	}

	
	printf("before sorting\n");
	rulesFile = fopen(RULES_FILE,"r");

	i = 0;

	while(fscanf(rulesFile,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",&rules[i][0],&rules[i][1],&rules[i][2],&rules[i][3],&rules[i][4],&rules[i][5],&rules[i][6],&rules[i][7],&rules[i][8],&rules[i][9],&rules[i][10]) != -1){
		i++;
		
	}
	totalRules = i;

	fclose(rulesFile);
			

	
	/*
	sorting

	*/
	
	printf("before sorting\n");
	qsort(rules,totalRules,sizeof( int*),comparefun2);
	printf("after sorting\n");

	int valAnt = -1;
	int ind = 0;

	for (i=0;i<totalRules;i++){
		for (j=0;j<RULE_SIZE;j++){
			printf("%d ", rules[i][j]);

		}
		printf("\n");
	}

	for(i=0;i<5;i++){
		printf("%d\n",ruleStartIndex[i]);
	}

	inputsFile = fopen(INPUTS_FILE,"r");
	
	int *input;
	input = malloc(sizeof(int)* RULE_SIZE);


	
	tstart = time(0);
	int ntransactions = 0;
	while (fscanf(inputsFile,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",&input[0],&input[1],&input[2],&input[3],&input[4],&input[5],&input[6],&input[7],&input[8],&input[9]) != -1) {

		

		for(j=0;j<totalRules;j++){

			
			if (compareVector(input,rules[j])!= -1){
				printVectorRule(input,rules[j]);
			}

		}

		ntransactions++;
	}

	tend = time(0);
	printf("Trans/seg: %f\n",(float )ntransactions /difftime(tend, tstart));

	fclose(inputsFile);

system("pause");

	return 0;

}