Пример #1
0
/**
 * Initialize the TAS thread pool -> create threads
 * @param workers Number of workers
 * */
void tas_init(int workers) {
	int i;

	logStart("tas_init");

	worker_total_count = workers;

#if TAS_POSIX == 0
	barrier_init(&worker_init_barrier, workers + 1);
	ticket_init(&worker_available_lock);
#else
	pthread_barrier_init(&worker_init_barrier, NULL, workers + 1);
#endif

#if TAS_DEBUG == 1
	PFL
	printf("MAIN - START tas_init with %i workers\n", workers);
	PFU
#endif

	// Initialize structures for threads
	for (i = 0; i < worker_total_count; i++) {
		worker_threads_data[i].do_shutdown = 0;
		worker_threads_data[i].work_assigned = 0;
		worker_threads_data[i].pattern_assigned = 0;
		worker_threads_data[i].thread_id = i;

		// Initialize barriers (n + 1)
#if TAS_POSIX == 1
		pthread_barrier_init(&(worker_threads_data[i].pattern_assigned_barrier_idle),
				NULL, 2);
		pthread_barrier_init(&(worker_threads_data[i].pattern_assigned_barrier),
				NULL, 2);
#else
		barrier_init(&(worker_threads_data[i].pattern_assigned_barrier), 2);
		barrier_init(&(worker_threads_data[i].pattern_assigned_barrier_idle), 2);
#endif
	}

	// Start worker threads
#if TAS_POSIX == 1
	for (i = 0; i < worker_total_count; i++) {
		pthread_create(&(thread_tasks[i]), NULL, tas_thread,
				&(worker_threads_data[i]));
	}
#else
	// Threads are started automatically
#endif

#if TAS_DEBUG == 1
	PFL
	printf("MAIN - END tas_init\n");
	PFU
#endif

	logEnd("tas_init");
}
Пример #2
0
void testApp::toLog(const std::string& to_log){

	static bool initLog = false;

	if(!initLog){
		sprintf(logFilename, "log_%02d_%02d_%02d_%02d_%02d.txt", ofGetMonth(), ofGetDay(), ofGetHours(), ofGetMinutes(), ofGetSeconds());
		log.append("Clouds Visual Systems Test Log \n ================================================ \n ");
		initLog = true;
	}

	log.append(to_log);
	logEnd();
}
Пример #3
0
void TupleAnnexStep::printCalTrace()
{
    time_t t = time (0);
    char timeString[50];
    ctime_r (&t, timeString);
    timeString[strlen (timeString )-1] = '\0';
    ostringstream logStr;
    logStr  << "ses:" << fSessionId << " st: " << fStepId << " finished at "<< timeString
            << "; total rows returned-" << fRowsReturned << endl
            << "\t1st read " << dlTimes.FirstReadTimeString()
            << "; EOI " << dlTimes.EndOfInputTimeString() << "; runtime-"
            << JSTimeStamp::tsdiffstr(dlTimes.EndOfInputTime(), dlTimes.FirstReadTime())
            << "s;\n\tJob completion status " << status() << endl;
    logEnd(logStr.str().c_str());
    fExtendedInfo += logStr.str();
    formatMiniStats();
}
Пример #4
0
/** Finalize the TAS thread pool -> destroy threads */
void tas_finalize() {
	int i;

	logStart("tas_finalize");

	if (tas_abstract_init_first) {
#if TAS_INFO == 1
		PFL
		printf("MAIN - Wait for workers... (worker_init_barrier) \n");
		PFU
#endif

		barrier_wait(&worker_init_barrier); // ID=tas_finalize_worker_init_barrier

#if TAS_INFO == 1
		PFL
		printf("MAIN - Passed worker_init_barrier.\n");
		PFU
#endif
		tas_abstract_init_first = 0;
	}

	// Set flags for shut down
	for (i = 0; i < worker_total_count; i++) {
		worker_threads_data[i].do_shutdown = 1;
		/* worker_threads_data[i].work_assigned = 0;
		 worker_threads_data[i].pattern_assigned = 0; */
	}


	// Wait for them to eat the poison and join threads
	for (i = 0; i < worker_total_count; i++) {
		barrier_wait(
				&(worker_threads_data[i].pattern_assigned_barrier_idle)); // ID=tas_finalize_pattern_assigned_barrier_idle
		barrier_wait(
				&(worker_threads_data[i].pattern_assigned_barrier)); // ID=tas_finalize_pattern_assigned_barrier
#if TAS_POSIX == 1
		pthread_join(thread_tasks[i], NULL);
#endif
	}


	logEnd("tas_finalize");
}
Пример #5
0
int main (int argc, char *argv[]){
	string logFilename ="";
	if (argc >= 2){
		logFilename = argv[1];
	}
	logInit(LOG_WARNING, logFilename);
	int b = 10;
	
	func1(b);
	func3(b);
	thread Thr=thread(func3, b);
	Thr.join();
	setLogLevel(LOG_INFO);
	
	func1(b);
	func3(b);
	logEnd();
	
}
Пример #6
0
void findWaypoints() {
	int position[3]; // Current position
	int i;
	double path_length = 0; // Total length of the path
	int path_steps = 0; // Total length of the path in steps

	logStart("findWaypoints");

	position[0] = getPosition()[0];
	position[1] = getPosition()[1];
	position[2] = getPosition()[2];

	for (i = 0; i < 1024; i++) {
		int a, b, c;

		double best_value = world[position[0]][position[1]][position[2]]; // So far best weigt == current weight
		int next[3] = { -1, -1, -1 }; // Next position

		for (a = -1; a <= 1; a++) {
			if (position[0] + a >= 0 && position[0] + a < WORLD_SIZE_X) {
				for (b = -1; b <= 1; b++) {
					if (position[1] + b >= 0 && position[1] + b < WORLD_SIZE_Y) {
						for (c = -1; c <= 1; c++) {
							if (position[2] + c >= 0 && position[2] + c < WORLD_SIZE_Z) {
								if (!isObstacle(position[0] + a, position[1] + b, position[2] + c)) {
									double new_value = world[position[0] + a][position[1] + b][position[2] + c];
									/* if (LL_DEBUG || 1)
									 printf(
									 "Surrounding point [%i, %i, %i] has value %2.12f (%e) - best know has value %2.12f (%e)\n",
									 position[0] + a, position[1]
									 + b, position[2] + c,
									 new_value, best_value); */
									if (new_value > best_value) {
										best_value = new_value;
										next[0] = position[0] + a;
										next[1] = position[1] + b;
										next[2] = position[2] + c;
									}
								}
							}
						}
					}
				}
			}
		}

		printf("Next waypoint: [%i, %i, %i] with value %2.12f (%e)\n", next[0], next[1], next[2], best_value,
				best_value);

		// Calculate path length
		int del_0 = position[0] - next[0];
		int del_1 = position[1] - next[1];
		int del_2 = position[2] - next[2];

		del_0 *= del_0;
		del_1 *= del_1;
		del_2 *= del_2;

		if (del_0 + del_1 + del_2 == 1)
			path_length += 1;
		if (del_0 + del_1 + del_2 == 2)
			path_length += 1.414; // SQRT(2)
		if (del_0 + del_1 + del_2 == 3)
			path_length += 1.732; // SQRT(3)

		path_steps++;

		if (isGoal(next[0], next[1], next[2]))
			break;
		else {
			// Set found waypoint as next position
			position[0] = next[0];
			position[1] = next[1];
			position[2] = next[2];
		}

	}

	printf("Total path length: %f\n", path_length);
	printf("Total path length in steps: %i\n", path_steps);

	logEnd("findWaypoints");
}
Пример #7
0
void demo_7_main_core_0() {

	int threads = TOTAL_PROC_NUM;

	// Initialize obstacle map from heightmap
	if (1) {
		logStart("initialize obstacle map");

		// Recode heightmap to global_obstacles
		int a, b, c;

		for (a = 0; a < WORLD_SIZE_X; a++) {
			for (b = 0; b < WORLD_SIZE_Y; b++) {
				int height = getHeightmapValue(a, b);

				// some regions cannot be flown over
				if (height > 174)
					height = 255;

				for (c = 0; c < height; c++) {
					global_obstacles[a][b][c] = 1;
				}
				for (c = height; c < WORLD_SIZE_Z; c++) {
					global_obstacles[a][b][c] = 0;
				}
			}
		}

		logEnd("initialize obstacle map");
	}

	// Set goal
	setGoal(WORLD_SIZE_X - 3, WORLD_SIZE_Y - 3, getHeightmapValue(WORLD_SIZE_X - 3, WORLD_SIZE_Y - 3) + 2);

	// Set current position
	setPosition(3, 3, getHeightmapValue(3, 3) + 2);

	// Init weightmap from obstacle map
	if (1) {
		int a, b, c;

		logStart("initialize weightmap from obstacle map");

		for (a = 0; a < WORLD_SIZE_X; a++) {
			for (b = 0; b < WORLD_SIZE_Y; b++) {
				for (c = 0; c < WORLD_SIZE_Z; c++) {
					if (isGoal(a, b, c)) {
						world[a][b][c] = WEIGHT_SINK;
					} else if (isObstacle(a, b, c)) {
						world[a][b][c] = WEIGHT_OBSTACLE;
					} else {
						world[a][b][c] = WEIGHT_INIT;
					}
				}
			}
		}

		logEnd("initialize weightmap from obstacle map");
	}

	// Propagate weights with selected algorithm
	promote_world(ITERATIONS, threads);

	// Find waypoints to goal
	findWaypoints();

	printf("Iterations: %i\n", ITERATIONS);

	return;
}