Exemplo n.º 1
0
 void object::test<2>() {
     ensure_equals(
             GEOS_VERSION,
             std::string(EXPAND_AND_QUOTE(GEOS_VERSION_MAJOR)) + "." +
             std::string(EXPAND_AND_QUOTE(GEOS_VERSION_MINOR)) + "." +
             std::string(EXPAND_AND_QUOTE(GEOS_VERSION_PATCH)));
 }
static int set_netem(void *data)
{
	struct jt_msg_netem_params *p1 = data;
	struct netem_params p2 = {
		.delay = p1->delay, .jitter = p1->jitter, .loss = p1->loss,
	};

	netem_set_params(p1->iface, &p2);
	jt_srv_send_select_iface();
	jt_srv_send_netem_params();
	jt_srv_send_sample_period();
	return 0;
}

static int select_iface(void *data)
{
	char(*iface)[MAX_IFACE_LEN] = data;

	if (!is_iface_allowed(*iface)) {
		fprintf(stderr, "ignoring request to switch to iface: [%s] - "
		                "iface not in allowed list: [%s]\n",
		        *iface, EXPAND_AND_QUOTE(ALLOWED_IFACES));
		return -1;
	}
	snprintf(g_selected_iface, MAX_IFACE_LEN, "%s", *iface);
	printf("switching to iface: [%s]\n", *iface);
	stats_monitor_iface(*iface);
	jt_srv_send_select_iface();
	jt_srv_send_netem_params();
	jt_srv_send_sample_period();
	return 0;
}
Exemplo n.º 3
0
 static std::unique_ptr<options::OptionParser> makeParser(bool simulating) {        
     std::unique_ptr<options::OptionParser> parser = SharedOptions::makeParser(simulating,
             EXPAND_AND_QUOTE(ROOT_PATH) "/problems/manipulator_continuous");
     addManipulatorOptions(parser.get());
     //addHeuristicOptions(parser.get());
     return std::move(parser);
 }
//======================================================================================================================
//======================================================================================================================
//======================================================================================================================
STKUNIT_UNIT_TEST(perceptMesh, open_new_close_PerceptMesh_2)
{
    EXCEPTWATCH;

    double x=0.123, y=0.234, z=0.345, time=0.0;

    // start_demo_open_new_close_PerceptMesh_2
    PerceptMesh eMesh(3u);
    // open the file we previously saved with the new fields
    eMesh.open_read_only(input_files_loc+"cube_with_pressure.e");

    eMesh.print_info("Info after reading mesh");

    //eMesh.print_fields();
    mesh::FieldBase *f_coords = eMesh.get_field("coordinates");

    // create a field function from the existing coordinates field
    FieldFunction ff_coords("ff_coords", f_coords, eMesh, 3, 3);

    // here we could evaluate this field function
    eval_vec3_print(x, y, z, time, ff_coords);

    // get the pressure field
    mesh::FieldBase* pressure_field = eMesh.get_field("pressure");

    // FIXME
    std::vector< const mesh::FieldBase * > sync_fields( 1 , pressure_field );
    mesh::communicate_field_data( eMesh.get_bulk_data()->shared_aura() , sync_fields );
    // FIXME

    //double * pdata = eMesh.node_field_data(pressure_field, 1);

    FieldFunction ff_pressure("ff_pressure", pressure_field, eMesh, 3, 1);
    ff_pressure.add_alias("P");
    StringFunction sf_pressure("P");

    // a point-source at the origin
#define EXACT_SOL log(sqrt( x*x + y*y + z*z) + 1.e-10)

    StringFunction sf_exact_solution(EXPAND_AND_QUOTE(EXACT_SOL), Name("sf_exact_solution"), 3, 1);
    StringFunction sf_error = sf_exact_solution - sf_pressure;

    eval_print(x,y,z,time, sf_error);
    double val_cpp = EXACT_SOL - pressure_value;
    double val_sf  = eval(x,y,z,time, sf_error);
    EXPECT_DOUBLE_EQ(val_sf, val_cpp);
    // end_demo

}
Exemplo n.º 5
0
    void object::test<1>() {
        ensure(std::string(EXPAND_AND_QUOTE(GEOS_VERSION_MAJOR)).length() > 0);
        ensure(std::string(EXPAND_AND_QUOTE(GEOS_VERSION_MINOR)).length() > 0);
        ensure(std::string(EXPAND_AND_QUOTE(GEOS_VERSION_PATCH)).length() > 0);
        ensure(std::string(GEOS_VERSION).length() > 0);

        ensure(std::string(EXPAND_AND_QUOTE(GEOS_CAPI_VERSION_MAJOR)).length() > 0);
        ensure(std::string(EXPAND_AND_QUOTE(GEOS_CAPI_VERSION_MINOR)).length() > 0);
        ensure(std::string(EXPAND_AND_QUOTE(GEOS_CAPI_VERSION_PATCH)).length() > 0);
        ensure(std::string(GEOS_CAPI_VERSION).length() > 0);
    }
int jt_srv_send_iface_list()
{
	struct jt_iface_list *il;
	char **iface;
	int idx;
	char **ifaces = netem_list_ifaces();

	il = malloc(sizeof(struct jt_iface_list));
	assert(il);

	il->count = 0;
	iface = ifaces;
	assert(NULL != iface);
	if (NULL == *iface) {
		fprintf(stderr, "No interfaces available. "
		                "Allowed interfaces (compile-time): %s\n",
		        EXPAND_AND_QUOTE(ALLOWED_IFACES));
	} else {
		do {
			printf("iface: %s\n", *iface);
			(il->count)++;
			iface++;
		} while (*iface);
	}

	printf("%d ifaces\n", il->count);

	assert(il->count);
	assert(MAX_IFACE_LEN);

	il->ifaces = malloc(il->count * MAX_IFACE_LEN);
	assert(il->ifaces);

	for (iface = ifaces, idx = 0; NULL != *iface && idx < il->count;
	     idx++) {
		printf("iface: %s\n", *iface);
		strncpy(il->ifaces[idx], *iface, MAX_IFACE_LEN);
		free(*iface);
		iface++;
	}

	free(ifaces);
	return jt_srv_send(JT_MSG_IFACE_LIST_V1, il);
}
static void get_first_iface(char *iface)
{
	char **ifaces = netem_list_ifaces();
	char **i = ifaces;
	assert(NULL != i);
	if (NULL == *i) {
		fprintf(stderr, "No interfaces available. "
		                "Allowed interfaces (compile-time): %s\n",
		        EXPAND_AND_QUOTE(ALLOWED_IFACES));
	}
	snprintf(iface, MAX_IFACE_LEN, "%s", *i);

	while (*i) {
		free(*i);
		i++;
	}

	free(ifaces);
}
Exemplo n.º 8
0
int is_iface_allowed(const char *needle)
{
	const char *haystack = EXPAND_AND_QUOTE(ALLOWED_IFACES);
	char *tokens = strdup(haystack);
	char *iface;

	if (0 == strlen(haystack)) {
		free(tokens);
		return 1;
	}

	iface = strtok(tokens, ":");
	while (iface) {
		if (0 == strcmp(iface, needle)) {
			free(tokens);
			return 1;
		}
		iface = strtok(NULL, ":");
	}
	free(tokens);
	return 0;
}
int main()
{
//	unsigned long start_time = time_ms();

	// init matrix
	memset(u, 0, N*N*sizeof(VALUE));

	printf("Jacobi with  N=%d, L_SZ=%d, IT=%d\n", N, L_SZ, IT);
	printf("Kernel file name: %s\n", KERNEL_FILE_NAME);

	// init F
	for(int i=0; i<N; i++)
		for(int j=0; j<N; j++)
			f[i][j] = init_func(i, j);

	VALUE factor = pow((VALUE)1/N, 2);

	// ocl initialization
	cl_context context;
	cl_command_queue command_queue;
	cl_device_id device_id = cluInitDevice(CL_DEVICE, &context, &command_queue);

	// create memory buffers
	cl_int err;
	cl_mem matrix_U = clCreateBuffer(context, CL_MEM_READ_WRITE, N * N * sizeof(VALUE), NULL, &err);
	cl_mem matrix_F = clCreateBuffer(context, CL_MEM_READ_ONLY, N * N * sizeof(VALUE), NULL, &err);
	cl_mem matrix_TMP = clCreateBuffer(context, CL_MEM_READ_WRITE, N * N * sizeof(VALUE), NULL, &err);
	CLU_ERRCHECK(err, "Failed to create buffer for matrix");

	// used for profiling info
	cl_event ev_write_U;
	cl_event ev_write_F;
	cl_event ev_kernel;
	cl_event ev_read_TMP;

	double write_total, read_total, kernel_total;
	write_total = read_total = kernel_total = 0.0;

	// create kernel from source
	char tmp[1024];
	sprintf(tmp, "-DN=%i -DVALUE=%s", N, EXPAND_AND_QUOTE(VALUE));
	cl_program program = cluBuildProgramFromFile(context, device_id, KERNEL_FILE_NAME, tmp);
	cl_kernel kernel = clCreateKernel(program, "jacobi", &err);
	CLU_ERRCHECK(err, "Failed to create matrix_mul kernel from program");

	/* ---------------------------- main part ----------------------------------- */

	// also initialize target matrix with zero values!!!
	err = clEnqueueWriteBuffer(command_queue, matrix_TMP, CL_TRUE, 0, N * N * sizeof(VALUE), u, 0, NULL, &ev_write_U);
	CLU_ERRCHECK(err, "Failed to write matrix to device");
	// write f to device
	err = clEnqueueWriteBuffer(command_queue, matrix_F, CL_FALSE, 0, N * N * sizeof(VALUE), f, 0, NULL, &ev_write_F);
	CLU_ERRCHECK(err, "Failed to write matrix F to device");

	// write matrix u to device
	err = clEnqueueWriteBuffer(command_queue, matrix_U, CL_FALSE, 0, N * N * sizeof(VALUE), u, 0, NULL, &ev_write_U);
	CLU_ERRCHECK(err, "Failed to write matrix U to device");

	// define global work size
	size_t g_work_size[2] = {N, N};
	size_t l_work_size[2] = {L_SZ, L_SZ};

	cl_mem buffer_u;
	cl_mem buffer_tmp;

	for (int i = 0; i < IT; ++i) {
		// swap U and TMP arguments based on iteration counter
		if(i % 2 == 0) {
			buffer_u = matrix_U;
			buffer_tmp = matrix_TMP;
		} else {
			buffer_u = matrix_TMP;
			buffer_tmp = matrix_U;
		}
		// compute memory block dimensions
		int block_dim = (L_SZ + 2) * (L_SZ + 2);
		// set kernel arguments
		cluSetKernelArguments(kernel, 5,
							  sizeof(cl_mem), (void *)&buffer_u,
							  sizeof(cl_mem), (void *)&matrix_F,
							  sizeof(cl_mem), (void *)&buffer_tmp,
							  // local memory buffer
							  block_dim * sizeof(VALUE), NULL,
							  sizeof(VALUE), (void *)&factor);

		// execute kernel
		err = clEnqueueNDRangeKernel(command_queue, kernel, 2, NULL, g_work_size, l_work_size, 0, NULL, &ev_kernel);
		CLU_ERRCHECK(err, "Failed to enqueue 2D kernel");
		// wait until execution completes
		clWaitForEvents(1, &ev_kernel);
		// add profiling information
		kernel_total += getDurationMS(ev_kernel);
	}

	// copy results back to host
	err = clEnqueueReadBuffer(command_queue, buffer_tmp, CL_TRUE, 0, N * N * sizeof(VALUE), u, 0, NULL, &ev_read_TMP);
	CLU_ERRCHECK(err, "Failed reading back result");

	// compute profiling information
	write_total += getDurationMS(ev_write_U);
	write_total += getDurationMS(ev_write_F);
	read_total += getDurationMS(ev_read_TMP);


	/* ---------------------------- evaluate results ---------------------------------- */
	// print result
	printf("OCL Device: %s\n", cluGetDeviceDescription(device_id, CL_DEVICE));
//	printf("Verification: %4s\n", (success) ? "OK" : "ERR");

	printf("Write total:      %9.4f ms\n", write_total);
	printf("Read total:       %9.4f ms\n", read_total);
	printf("Kernel execution: %9.4f ms\n", kernel_total);
	printf("Time total:       %9.4f ms\n\n", write_total + read_total + kernel_total);
#ifdef DEBUG
	print_result(u);
#endif



	/* ---------------------------- finalization ------------------------------------- */

	err = clFinish(command_queue);
	err |= clReleaseKernel(kernel);
	err |= clReleaseProgram(program);
	err |= clReleaseMemObject(matrix_U);
	err |= clReleaseMemObject(matrix_F);
	err |= clReleaseMemObject(matrix_TMP);
	err |= clReleaseCommandQueue(command_queue);
	err |= clReleaseContext(context);
	CLU_ERRCHECK(err, "Failed during ocl cleanup");

	return EXIT_SUCCESS;
}
Exemplo n.º 10
0
const char *get_svn_revision(void) {
		return EXPAND_AND_QUOTE(SVNVERSION);
	}
Exemplo n.º 11
0
void Codri::UserInterface::showError() {
    unload();
    load(QString("file://%1/errorpage.html").arg(EXPAND_AND_QUOTE(DATADIR)));
}
Exemplo n.º 12
0
 /** Constructs an OptionParser instance that will parse configuration settings for the GwAima
  * problem into an instance of GwAimaOptions.
  */
 static std::unique_ptr<options::OptionParser> makeParser(bool simulating) {
     std::unique_ptr<options::OptionParser> parser = SharedOptions::makeParser(simulating,
             EXPAND_AND_QUOTE(ROOT_PATH) "/problems/gwaima");
     addGwAimaOptions(parser.get());
     return std::move(parser);
 }
Exemplo n.º 13
0
int main(int argc, char** argv){
	
	srand(time(NULL));
	
	if(argc != 2) {
		printf("Usage: search [elements]\nExample: scan 10000\n");
		return -1;
	}
	
	unsigned long long start_time = time_ms();
	int event_amount=2;
	int elems = atoi(argv[1]);
	
	cl_int err;
	cl_event* events=allocateMemoryForEvent(event_amount);
	cl_ulong total_downsweep=0,total_hillissteele=0;
	size_t localWorkGroupSize_downSweep[1]={LOCALSIZE};	//must be power of two
	size_t globalWorkGroupSize_downSweep[1]={getPowerOfTwo(roundUp(LOCALSIZE,roundUp(LOCALSIZE, elems)/2))};	//calculating
	
	size_t localWorkGroupSize_hillissteele[1]={LOCALSIZE};	//must be power of two
	size_t globalWorkGroupSize_hillissteele[1]={roundUp(LOCALSIZE,elems)};	//calculating worksize
	
	
	int howManyWorkGroups=globalWorkGroupSize_downSweep[0]/LOCALSIZE;	//quotient is power of two, since dividend and divisor are power of two
	int sumBuffer_length_downSweep=howManyWorkGroups;
	int sumBuffer_length_hillis=getPowerOfTwo(roundUp(LOCALSIZE,elems)/LOCALSIZE);	

	VALUE *data = (VALUE*)malloc(elems*sizeof(VALUE));
	VALUE *result_seq=(VALUE*)malloc(elems*sizeof(VALUE));
	VALUE *result=(VALUE*)malloc(elems*sizeof(VALUE));
	VALUE *result_hillissteele=(VALUE*)malloc(elems*sizeof(VALUE));
	VALUE *sum=(VALUE*)malloc(sumBuffer_length_downSweep*sizeof(VALUE));
	VALUE *sum_hillis=(VALUE*)malloc(sumBuffer_length_hillis*sizeof(VALUE));
	

	memset(sum_hillis,0,sumBuffer_length_hillis*sizeof(VALUE));
	memset(result_seq,0,elems*sizeof(VALUE));
	
	// initialize data set (fill randomly)
	for(int j=0; j<elems; ++j) {
		data[j] =rand()%121;
	}
	
//	printResult(data, elems, 4, "INPUT");
	
	/*Sequential Scan*/
	for(int i=1; i<elems; i++){
	    result_seq[i]=result_seq[i-1]+data[i-1];
	}
	
//	printResult(result_seq, elems, 4, "Sequential Algorithm OUTPUT");
		
	//ocl initialization
	size_t deviceInfo;
	cl_context context;
	cl_command_queue command_queue;
	cl_device_id device_id = cluInitDevice(CL_DEVICE, &context, &command_queue);
	clGetDeviceInfo(device_id, CL_DEVICE_MAX_WORK_GROUP_SIZE,sizeof(size_t), &deviceInfo,NULL );
  
	
	// create memory buffer
	cl_mem mem_data=clCreateBuffer(context, CL_MEM_READ_ONLY| CL_MEM_USE_HOST_PTR,elems*sizeof(VALUE), data, &err);
 	cl_mem mem_data_hillis=clCreateBuffer(context, CL_MEM_READ_ONLY| CL_MEM_USE_HOST_PTR,elems*sizeof(VALUE), data, &err);
	cl_mem mem_result=clCreateBuffer(context, CL_MEM_READ_WRITE, elems*sizeof(VALUE), NULL,&err);
	cl_mem mem_result_tmp=clCreateBuffer(context, CL_MEM_READ_WRITE, elems*sizeof(VALUE), NULL,&err);
	cl_mem mem_sum=clCreateBuffer(context, CL_MEM_READ_WRITE, sumBuffer_length_downSweep*sizeof(VALUE), NULL, &err);
	cl_mem mem_sum_hillis=clCreateBuffer(context, CL_MEM_READ_WRITE, sumBuffer_length_hillis*sizeof(VALUE), NULL, &err);
	CLU_ERRCHECK(err, "Failed to create Buffer");
    
	err=clEnqueueWriteBuffer(command_queue, mem_sum_hillis, CL_TRUE, 0, sumBuffer_length_hillis*sizeof(VALUE), sum_hillis, 0, NULL, NULL);
	CLU_ERRCHECK(err, "Failed to write values into mem_sum");
	

	// create kernel from source
	char tmp[1024];
 	sprintf(tmp,"-DVALUE=%s", EXPAND_AND_QUOTE(VALUE));
	cl_program program = cluBuildProgramFromFile(context, device_id, KERNEL_FILE_NAME, tmp);
	cl_kernel kernel_downSweep = clCreateKernel(program, "prefix_scan_downSweep", &err);
	cl_kernel kernel_hillissteele=clCreateKernel(program, "prefix_scan_hillissteele", &err);
	cl_kernel kernel_last_stage= clCreateKernel(program, "prefix_scan_last_stage", &err);
	CLU_ERRCHECK(err,"Could not load source program");
    

	
	/*-------------------------------------DOWNSWEEP-----------------------------------------------*/
	// set arguments
	int border=elems/2;
	int flag=1;
	
	cluSetKernelArguments(kernel_downSweep, 6, sizeof(cl_mem), (void *)&mem_data, sizeof(cl_mem), (void*)&mem_result,
			      sizeof(cl_mem), (void*)&mem_sum,sizeof(VALUE)*LOCALSIZE*2, NULL, sizeof(int), (void*)&border,
			      sizeof(int), (void*)&flag);

	//execute kernel  	     
	CLU_ERRCHECK(clEnqueueNDRangeKernel(command_queue, kernel_downSweep, 1, NULL, globalWorkGroupSize_downSweep, localWorkGroupSize_downSweep, 0, NULL, &(events[1])), "DownSweep_Failed to enqueue 2D kernel");		      
	clFinish(command_queue);
	total_downsweep+=getProfileTotalTime(events,1);
	
	//read values back from device
	CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_result, CL_TRUE, 0, elems*sizeof(VALUE), result, 0, NULL, NULL),"DownSweep_Failed to read Result Values");
	
	/*
	CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_sum, CL_TRUE, 0, sumBuffer_length_downSweep*sizeof(VALUE), sum, 0, NULL, NULL),"Failed to read Sum Values");
	clFinish(command_queue);
	printSumBuffer(sum, sumBuffer_length_downSweep,"DOWNSWEEP SUM");
	*/
	err=clEnqueueCopyBuffer(command_queue, mem_result, mem_result_tmp, 0, 0, elems*sizeof(VALUE),0,NULL,NULL);
	CLU_ERRCHECK(err,"DownSweep_Failed during copying buffer");
	
	
	/*+++++++++++++++++++++++++++++++++DOWNSWEEP-ON-SUM-BUFFER+++++++++++++++++++++++++++++++++++++++*/
	flag=0;
	border=sumBuffer_length_downSweep/2;	//since sumbuffer_length is power of two no further adaption is needed
	cluSetKernelArguments(kernel_downSweep, 6, sizeof(cl_mem), (void *)&mem_sum, sizeof(cl_mem), (void*)&mem_sum,
			      sizeof(cl_mem), (void*)&mem_sum,sizeof(VALUE)*sumBuffer_length_downSweep, NULL, sizeof(int), (void*)&border,
			      sizeof(int), (void*)&flag);
	
	howManyWorkGroups>1 ? globalWorkGroupSize_downSweep[0]=howManyWorkGroups/2:howManyWorkGroups;	//if 1 workgroup make adaption
	howManyWorkGroups>1 ? localWorkGroupSize_downSweep[0]=howManyWorkGroups/2:howManyWorkGroups;	//if 1 workgroup make adaption
	
	
	//execute kernel
	CLU_ERRCHECK(clEnqueueNDRangeKernel(command_queue, kernel_downSweep, 1, NULL, globalWorkGroupSize_downSweep, localWorkGroupSize_downSweep, 0, NULL,&(events[1])), "DownSweep_Failed to enqueue 2D kernel");		      
	clFinish(command_queue);
	total_downsweep+=getProfileTotalTime(events,1);
	/*
	CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_sum, CL_TRUE, 0, sumBuffer_length_downSweep*sizeof(VALUE), sum, 0, NULL, NULL),"Failed to read Sum Values");	
	printSumBuffer(sum, sumBuffer_length_downSweep,"DOWNSWEEP SUM PREFIX");
	*/
	
	/*+++++++++++++++++++++++++++++++++DOWNSWEEP-LAST-STAGE(Add Sums)++++++++++++++++++++++++++++++++++++++++*/
	border=sumBuffer_length_downSweep;
	flag=1;
	cluSetKernelArguments(kernel_last_stage, 4, sizeof(cl_mem), (void *)&mem_result_tmp, sizeof(cl_mem), (void*)&mem_sum, sizeof(int), (void*)&border,
			      sizeof(int), (void*)&flag);
	globalWorkGroupSize_downSweep[0]=getPowerOfTwo(roundUp(LOCALSIZE,roundUp(LOCALSIZE, elems)/2));
	localWorkGroupSize_downSweep[0]=LOCALSIZE;
	
	//printf("GLOBALSIZE: %d\tLOCALSIZE %d\n",globalWorkGroupSize[0],localWorkGroupSize[0]);
	
	//execute kernel  	     
	CLU_ERRCHECK(clEnqueueNDRangeKernel(command_queue, kernel_last_stage, 1, NULL, globalWorkGroupSize_downSweep, localWorkGroupSize_downSweep, 0, NULL, &(events[1])), "DownSweep_Failed to enqueue 2D kernel");		      
	clFinish(command_queue);
	total_downsweep+=getProfileTotalTime(events,1);
	//read values back from device
	CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_result_tmp, CL_TRUE, 0, elems*sizeof(VALUE), result, 0, NULL, NULL),"DownSweep_Failed to read Result Values");
	
	
	/*---------------------------------------HILLISSTEELE----------------------------------------------------------*/
	
	
	flag=1;
	border=elems;
	
	cluSetKernelArguments(kernel_hillissteele, 6, sizeof(cl_mem), (void *)&mem_data_hillis, sizeof(cl_mem), (void*)&mem_result,
			      sizeof(cl_mem), (void*)&mem_sum_hillis,sizeof(VALUE)*LOCALSIZE*2, NULL, sizeof(int), (void*)&border,
			      sizeof(int), (void*)&flag);

	//execute kernel	
	//printf("GlobalSize: %d\tLocalWorkGroupSize: %d\n",globalWorkGroupSize[0], localWorkGroupSize[0]);
	//printf("Amount of WorkGroups: %d\n", globalWorkGroupSize[0]/localWorkGroupSize[0]);
	
	CLU_ERRCHECK(clEnqueueNDRangeKernel(command_queue, kernel_hillissteele, 1, NULL, globalWorkGroupSize_hillissteele, localWorkGroupSize_hillissteele, 0, NULL, &(events[0])), "Hillissteele_Failed to enqueue 2D kernel_Inputbuffer");		      
	
	clFinish(command_queue);
	total_hillissteele+=getProfileTotalTime(events,0);
	//read values back from device
	/*
	CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_result, CL_TRUE, 0, elems*sizeof(VALUE), result_hillissteele, 0, NULL, NULL),"Failed to read Result Values");
	CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_sum_hillis, CL_TRUE, 0, sumBuffer_length_hillis*sizeof(VALUE), sum_hillis, 0, NULL, NULL),"Failed to read Sum_1 Values");
	printSumBuffer(sum_hillis, sumBuffer_length_hillis, "HILLISSTEELE SUM");
	printResult(result_hillissteele,elems, 4, "HILLISSTEELE Temporary OUTPUT");
	*/
	
	
	/*++++++++++++++++++++++++++++++++++++++HILLISSTEELE-ON-SUM-BUFFER+++++++++++++++++++++++++++++++++++++*/
	
	flag=0;
	border=sumBuffer_length_hillis;
	cluSetKernelArguments(kernel_hillissteele, 6, sizeof(cl_mem), (void *)&mem_sum_hillis, sizeof(cl_mem), (void*)&mem_sum_hillis,
			      sizeof(cl_mem), (void*)&mem_sum_hillis,sizeof(VALUE)*howManyWorkGroups*2, NULL, sizeof(int), (void*)&border,
			      sizeof(int), (void*)&flag);

	//execute kernel
	globalWorkGroupSize_hillissteele[0]=sumBuffer_length_hillis;
	localWorkGroupSize_hillissteele[0]=sumBuffer_length_hillis;
	CLU_ERRCHECK(clEnqueueNDRangeKernel(command_queue, kernel_hillissteele, 1, NULL, globalWorkGroupSize_hillissteele, localWorkGroupSize_hillissteele, 0, NULL, &(events[0])), "Hillissteele_Failed to enqueue 2D kernel_Sumbuffer");		      
	
	clFinish(command_queue);
	total_hillissteele+=getProfileTotalTime(events,0);
	
	//read values back from device
	/*
	CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_sum_hillis, CL_TRUE, 0, sumBuffer_length_hillis*sizeof(VALUE), sum_hillis, 0, NULL, NULL),"Failed to read Sum2 Values");
	printSumBuffer(sum_hillis, sumBuffer_length_hillis, "HILLISSTEELE SUM PREFIX");
	*/
	
	/*+++++++++++++++++++++++++++++++++++++HILLISSTEELE-LAST-STAGE(Add Sums)++++++++++++++++++++++++++++++++++++++++*/
	
	flag=0;
	border=sumBuffer_length_hillis;
	cluSetKernelArguments(kernel_last_stage, 4, sizeof(cl_mem), (void *)&mem_result, sizeof(cl_mem), (void*)&mem_sum_hillis, sizeof(int), (void*)&border,
			      sizeof(int), (void*)&flag);
	
	globalWorkGroupSize_hillissteele[0]=roundUp(LOCALSIZE,elems);
	localWorkGroupSize_hillissteele[0]=LOCALSIZE;
	
	//printf("GLOBALSIZE: %d\tLOCALSIZE %d\n",globalWorkGroupSize[0],localWorkGroupSize[0]);
	
	//execute kernel  	     
	CLU_ERRCHECK(clEnqueueNDRangeKernel(command_queue, kernel_last_stage, 1, NULL, globalWorkGroupSize_hillissteele, localWorkGroupSize_hillissteele, 0, NULL, &(events[0])), "Hillissteele_Failed to enqueue kernel_Last_stage");		      
	clFinish(command_queue);
	total_hillissteele+=getProfileTotalTime(events,0);
	
	//read values back from device
	CLU_ERRCHECK(clEnqueueReadBuffer(command_queue, mem_result, CL_TRUE, 0, elems*sizeof(VALUE), result_hillissteele, 0, NULL, NULL),"Hillissteele_Failed to read Result Values");
	
	
	/*-------------------------FINISHED---------------------------------------------*/
	
	//printResult(result_hillissteele, elems, 4, "HILLISSTEELE OUTPUT");
	//printResult(result, elems, 4, "IMPROVED IMPLEMENTATION OUTPUT");
	
	//verify results
	verifyResult(result_seq,result,elems, "Verifying result of DownSweep for bigger array size");
	verifyResult(result_seq,result_hillissteele,elems, "Verifying result of HILLISSTEELE for bigger array size");
	
	
	printProfileInfo(total_downsweep,"Improved Algorithm Time:");
	printProfileInfo(total_hillissteele,"Hillis & Steele Time:");
	printf("\nDEVICE INFO MAX_WORK_GROUP_SIZE: %d\n", (int) deviceInfo);
	printf("OCL Device: %s\n", cluGetDeviceDescription(device_id, CL_DEVICE));
	printf("Done, took %16llu ms\n", time_ms()-start_time);
    
	
	
	// finalization
	
	for(int i=0; i<event_amount; i++){
	    clReleaseEvent(events[i]);
	}
	
	err =  clFinish(command_queue);
	err |= clReleaseKernel(kernel_downSweep);
	err |= clReleaseKernel(kernel_last_stage);
	err |= clReleaseKernel(kernel_hillissteele);
	err |= clReleaseProgram(program);
	err |= clReleaseMemObject(mem_data);
	err |= clReleaseMemObject(mem_data_hillis);
	err |= clReleaseMemObject(mem_result);
	err |= clReleaseMemObject(mem_result_tmp);
	err |= clReleaseMemObject(mem_sum);
	err |= clReleaseMemObject(mem_sum_hillis);
	err |= clReleaseCommandQueue(command_queue);
	err |= clReleaseContext(context);
	CLU_ERRCHECK(err, "Failed during ocl cleanup");
    
	free(events);
	free(result);
	free(result_hillissteele);
	free(result_seq);
	free(sum);
	free(sum_hillis);
	
	return EXIT_SUCCESS; 
}
//======================================================================================================================
//======================================================================================================================
//======================================================================================================================
STKUNIT_UNIT_TEST(perceptMesh, open_new_close_PerceptMesh)
{
    EXCEPTWATCH;

    // start_demo_open_new_close_PerceptMesh
    PerceptMesh eMesh(3u);
    eMesh.new_mesh(GMeshSpec("3x3x3|bbox:0,0,0,1,1,1"));  // create a 3x3x3 hex mesh in the unit cube
    int scalarDimension = 0; // a scalar
    int vectorDimension = 3;

    mesh::FieldBase* pressure_field = eMesh.add_field("pressure", stk::mesh::fem::FEMMetaData::NODE_RANK, scalarDimension);
    eMesh.add_field("velocity", stk::mesh::fem::FEMMetaData::NODE_RANK, vectorDimension);
    eMesh.add_field("element_volume", eMesh.element_rank(), scalarDimension);

    eMesh.commit();

    // create a field function from the new pressure field
    FieldFunction ff_pressure("ff_pressure", pressure_field, eMesh, 3, 1);

    // set the value of the pressure field to a constant everywhere
    ConstantFunction initPressureValues(pressure_value, "initPVal");
    ff_pressure.interpolateFrom(initPressureValues);

    //if (eMesh.get_rank()== 0) eMesh.print_fields("Pressure");
    //exit(1);

    // here we could evaluate this field function
    double x=0.123, y=0.234, z=0.345, time=0.0;
    std::cout << "P[" << eMesh.get_rank() << "] "
              << "before write ff_pressure = " << eval(x,y,z,time, ff_pressure) << std::endl;

    //eval_print(x, y, z, time, ff_pressure);

    double pval = eval(x, y, z, time, ff_pressure);
    EXPECT_DOUBLE_EQ(pval, pressure_value);

    eMesh.save_as(output_files_loc+"cube_with_pressure.e");
    eMesh.close();

    // end_demo

    // start_demo_open_new_close_PerceptMesh_1
    // open the file we previously saved with the new fields
    eMesh.open_read_only(input_files_loc+"cube_with_pressure.e");

    // get the pressure field
    pressure_field = eMesh.get_field("pressure");

    // FIXME
    std::vector< const mesh::FieldBase * > sync_fields( 1 , pressure_field );
    mesh::communicate_field_data( eMesh.get_bulk_data()->shared_aura() , sync_fields );
    // FIXME

    //if (1 || eMesh.get_rank()== 0) eMesh.print_fields("Pressure");

    FieldFunction ff_pressure_1("ff_pressure", pressure_field, eMesh, 3, 1);
    ff_pressure_1.add_alias("P");
    StringFunction sf_pressure("P");
    std::cout << "P[" << eMesh.get_rank() << "] "
              << "after read ff_pressure = " << eval(x,y,z,time, ff_pressure_1) << std::endl;

    // a point-source at the origin
#define EXACT_SOL log(sqrt( x*x + y*y + z*z) + 1.e-10)

    StringFunction sf_exact_solution(EXPAND_AND_QUOTE(EXACT_SOL), Name("sf_exact_solution"), 3, 1);
    StringFunction sf_error = sf_exact_solution - sf_pressure;

    std::cout << "P[" << eMesh.get_rank() << "] "
              << "sf_pressure = " << eval(x,y,z,time, sf_pressure) << std::endl;
    //!eval_print(x,y,z,time, sf_error);
    std::cout << "P[" << eMesh.get_rank() << "] "
              << "sf_error = " << eval(x,y,z,time, sf_error) << std::endl;
    double val_cpp = EXACT_SOL - pressure_value;
    double val_sf  = eval(x,y,z,time, sf_error);
    EXPECT_DOUBLE_EQ(val_sf, val_cpp);
    // end_demo

}
Exemplo n.º 15
0
Arquivo: parse.cpp Projeto: gk1/teev
 *
 *****************************************************************************/

#define DBG 0
#if 1
#include <stdio.h>
#endif
#include <stdlib.h>
#include <string.h>

#include "parse.h"
#include "functions.h"
#include "log.h"
#define CLASS_MODULE "parse"

const char *parse_libdvbpsi_version = EXPAND_AND_QUOTE(DVBPSI_VERSION);

#if USE_STATIC_DECODE_MAP
static map_decoder   decoders;
#endif

#define dprintf(fmt, arg...) __dprintf(DBG_PARSE, fmt, ##arg)

#define PID_PAT  0x00
#define PID_CAT  0x01
#define PID_TSDT 0x02
#define PID_NIT  0x10
#define PID_SDT  0x11
#define PID_BAT  0x11
#define PID_EIT  0x12
#define PID_RST  0x13
Exemplo n.º 16
0
const char* get_svn_revision(void) {
	static char svn_version_buffer[16] = "";
	FILE *fp;

	if( svn_version_buffer[0] != '\0' )
		return svn_version_buffer;

	// subversion 1.7 uses a sqlite3 database
	// FIXME this is hackish at best...
	// - ignores database file structure
	// - assumes the data in NODES.dav_cache column ends with "!svn/ver/<revision>/<path>)"
	// - since it's a cache column, the data might not even exist
	if( (fp = fopen(".svn" PATHSEP_STR "wc.db", "rb")) != NULL || (fp = fopen(".." PATHSEP_STR ".svn" PATHSEP_STR "wc.db", "rb")) != NULL )
	{
	#ifndef SVNNODEPATH
		//not sure how to handle branches, so i'll leave this overridable define until a better solution comes up
		#define SVNNODEPATH trunk
	#endif
		const char* prefix = "!svn/ver/";
		const char* postfix = "/" EXPAND_AND_QUOTE(SVNNODEPATH) ")"; // there should exist only 1 entry like this
		size_t prefix_len = strlen(prefix);
		size_t postfix_len = strlen(postfix);
		size_t i,j,len;
		char* buffer;

		// read file to buffer
		fseek(fp, 0, SEEK_END);
		len = ftell(fp);
		buffer = (char*)aMalloc(len + 1);
		fseek(fp, 0, SEEK_SET);
		len = fread(buffer, 1, len, fp);
		buffer[len] = '\0';
		fclose(fp);

		// parse buffer
		for( i = prefix_len + 1; i + postfix_len <= len; ++i ) {
			if( buffer[i] != postfix[0] || memcmp(buffer + i, postfix, postfix_len) != 0 )
				continue; // postfix missmatch
			for( j = i; j > 0; --j ) {// skip digits
				if( !ISDIGIT(buffer[j - 1]) )
					break;
			}
			if( memcmp(buffer + j - prefix_len, prefix, prefix_len) != 0 )
				continue; // prefix missmatch
			// done
			snprintf(svn_version_buffer, sizeof(svn_version_buffer), "%d", atoi(buffer + j));
			break;
		}
		aFree(buffer);

		if( svn_version_buffer[0] != '\0' )
			return svn_version_buffer;
	}

	// subversion 1.6 and older?
	if ((fp = fopen(".svn/entries", "r")) != NULL)
	{
		char line[1024];
		int rev;
		// Check the version
		if (fgets(line, sizeof(line), fp))
		{
			if(!ISDIGIT(line[0]))
			{
				// XML File format
				while (fgets(line,sizeof(line),fp))
					if (strstr(line,"revision=")) break;
				if (sscanf(line," %*[^\"]\"%11d%*[^\n]", &rev) == 1) {
					snprintf(svn_version_buffer, sizeof(svn_version_buffer), "%d", rev);
				}
			}
			else
			{
				// Bin File format
				if ( fgets(line, sizeof(line), fp) == NULL ) { printf("Can't get bin name\n"); } // Get the name
				if ( fgets(line, sizeof(line), fp) == NULL ) { printf("Can't get entries kind\n"); } // Get the entries kind
				if(fgets(line, sizeof(line), fp)) // Get the rev numver
				{
					snprintf(svn_version_buffer, sizeof(svn_version_buffer), "%d", atoi(line));
				}
			}
		}
		fclose(fp);

		if( svn_version_buffer[0] != '\0' )
			return svn_version_buffer;
	}

	// fallback
	svn_version_buffer[0] = UNKNOWN_VERSION;
	return svn_version_buffer;
}