Example #1
0
void Wb_plugin::exec_task(bool sync)
{
  set_task_proc();

  bec::GRTTask::Ref task = bec::GRTTask::create_task(task_desc(), _grtm->get_dispatcher(), _task_proc_cb);

  scoped_connect(task->signal_message(),boost::bind(&Wb_plugin::process_task_msg, this, _1));
  scoped_connect(task->signal_failed(),boost::bind(&Wb_plugin::process_task_fail, this, _1));
  scoped_connect(task->signal_finished(),boost::bind(&Wb_plugin::process_task_finish, this, _1));

  if (sync)
    _grtm->get_dispatcher()->add_task_and_wait(task);
  else
    _grtm->get_dispatcher()->add_task(task);
}
void Wb_plugin::exec_task(bool sync) {
  set_task_proc();

  bec::GRTTask::Ref task =
    bec::GRTTask::create_task(task_desc(), bec::GRTManager::get()->get_dispatcher(), _task_proc_cb);

  scoped_connect(task->signal_message(), std::bind(&Wb_plugin::process_task_msg, this, std::placeholders::_1));
  scoped_connect(task->signal_failed(), std::bind(&Wb_plugin::process_task_fail, this, std::placeholders::_1));
  scoped_connect(task->signal_finished(), std::bind(&Wb_plugin::process_task_finish, this, std::placeholders::_1));

  if (sync)
    bec::GRTManager::get()->get_dispatcher()->add_task_and_wait(task);
  else
    bec::GRTManager::get()->get_dispatcher()->add_task(task);
}
Example #3
0
struct task *task_new(struct parsed *prog)
{
	extern struct task *tasks;
	struct task *t, *thistask;
	struct job *jprev = NULL;
	struct parsed *iter;
	int jid = 1;

	for(t = tasks; t; t = t->next){
		struct job *j;
		for(j = t->jobs; j; j = j->next)
			if(j->job_id == jid){
				jid++;
				t = tasks;
				break;
			}
	}

	thistask = umalloc(sizeof *thistask);
	memset(thistask, 0, sizeof *thistask);

	thistask->state = TASK_BEGIN;

	for(iter = prog; iter; iter = iter->next){
		struct job *j = job_new(iter->argvp, jid, iter->redir);

		if(jprev)
			jprev->next = j;
		else
			thistask->jobs = j;
		jprev = j;
	}
	jprev->next = NULL;

	thistask->cmd = task_desc(thistask);

	return thistask;
}
Example #4
0
//initialize all tasks
int MATRIXClient::initializeTasks(int num_tasks_req, int numSleep, int mode, int max_tasks_per_package, ZHTClient &clientRet, int DAG_choice){

	srand(time(NULL)); // Random seed for all time measurements

	// Task description
        char task[10];  
        memset(task, '\0', 10);
        sprintf(task, "%d", numSleep); // sleep time - 1, 2, 4, 8, 16, 32
	string task_desc(task);

	int num_worker = clientRet.memberList.size();
        int toserver = (num_worker-1)/(selfindex+1); // Server index where the tasks will be initially submitted to the Wait queue
	//cout << "to server = " << toserver << endl;

	// Initialize a random DAG based on the number of tasks requested by client
	// Note: The number of tasks in the generated DAG may not be actually equal to what is requested
	//	 This is fine for now, as in real systems the actual DAG would be supplied rather than we generate one.
	int num_tasks; // number of tasks actually generated
	TaskDAG dag = generate_DAG(num_tasks_req, num_tasks, client_id, DAG_choice); //cout << "total tasks = " << num_tasks << endl;
	//total_num_tasks = num_tasks * num_worker;
	//total_num_tasks = num_tasks;
	//print_DAG(dag);

	// Submission time for the task; for simplicity it is kept same for all tasks
	timespec sub_time;
	clock_gettime(CLOCK_REALTIME, &sub_time);
	uint64_t sub_time_ns;
	sub_time_ns = (uint64_t)sub_time.tv_sec*1000000000 + (uint64_t)sub_time.tv_nsec;

	// Arguments to be passed to submission thread:
	// 1. Vector that holds serialized packages for each individual task, 
	// 2. ZHT Client for network communication, and 
	// 3. Number of tasks to be submitted
	submit_args thread_args;
	thread_args.task_str_list = &task_str_list;
	thread_args.clientRet = clientRet;
	thread_args.per_client_task = num_tasks;

	// Spin the submission thread with the structure containing the above mentioned arguments
	pthread_t submit_thread;
	//pthread_create(&submit_thread, NULL, submit, &thread_args);

	// Reserve space for the vector to hold serialized packages for each individual task
	task_str_list.reserve(num_tasks);

	// Measure the start time for task submission into NoVoHT
	clock_gettime(CLOCK_REALTIME, &start_tasks);

	// For all tasks in the DAG, package it and store it in NoVOHT
        //for(i = 0; i < num_tasks; i++){ 
	for(TaskDAG::iterator it = dag.begin(); it != dag.end(); ++it) {
		int task_id = it->first;
                TaskDAG_Value value(it->second);

		stringstream task_id_ss;
		task_id_ss << task_id << client_id; // Task ID + Client ID
		//cout << "id = " << task_id_ss.str();
		//cout << "numwait = " << value.first << " notlist = " << value.second << endl;

		Package package;
		package.set_virtualpath(task_id_ss.str()); // Key is task ID + client ID
		package.set_operation(3);		   // Insert task and its decription into NoVoHT
//		cout << "key = " << package.virtualpath();
//		cout << " op = " << package.operation() << endl;
//		string str1 = package.SerializeAsString(); // Serialize the package
//cout << " str1 = " << str1 << endl;

		stringstream to_index_ss;
		to_index_ss << toserver << "\'" << "\"";
		package.set_nodehistory(to_index_ss.str()); // History of migrations delimited by \' with a final \"
//		cout << "nodehistory = " << package.nodehistory();
		package.set_currnode(toserver); 	    // Current node
//		cout << " currnode = " << package.currnode();
		package.set_nummoves(0); 		    // Number of migrations, initially it is zero
//		cout << " nummoves = " << package.nummoves();
		package.set_numwait(value.first); 	    // Number of notifications to receive before it can be moved to ready queue
//		cout << " numwait = " << package.numwait() << endl;
		//package.set_notlist(value.second);	    // List of tasks to be notified after finishing execution
		//cout << "notlist = " << package.notlist() << endl;
//		string str2 = package.SerializeAsString();  // Serialize the package
//cout << " str2 = " << str2 << endl;

		stringstream package_content_ss;
		//package_content_ss << value.second; // List of tasks to be notified after finishing execution
		package_content_ss << "NULL"; package_content_ss << "\'"; 				// Task completion status
		package_content_ss << task_desc; package_content_ss << "\'"; 				// Task Description
		package_content_ss << task_id_ss.str();	package_content_ss << "\'"; 			// Task ID
		package_content_ss << sub_time_ns; package_content_ss << "\'"; package_content_ss << "\""; // Task Submission Time
		package_content_ss << value.second; // List of tasks to be notified after finishing execution
		package.set_realfullpath(package_content_ss.str());
		string str = package.SerializeAsString(); // Serialize the package
//cout << " str = " << str << endl;
		//pthread_mutex_lock(&submit_q);
		// Push the serialized task into a vector which is shared by another thread that handles the submission over the network
		task_str_list.push_back(str);
		//pthread_mutex_unlock(&submit_q);
       	}
	clock_gettime(CLOCK_REALTIME, &end_tasks); timespec diff1 = timediff(start_tasks, end_tasks);
        cout << "novoht jobs created. TIME TAKEN: " << diff1.tv_sec << "  SECONDS  " << diff1.tv_nsec << "  NANOSECONDS" << endl;

        get_map(task_str_list, num_worker);

        clock_gettime(CLOCK_REALTIME, &start_tasks);

        submittasks(clientRet);

	//pthread_join(submit_thread, NULL); // Wait for the submission thread to finish sending the tasks over the network
	clock_gettime(CLOCK_REALTIME, &end_tasks); // Measure the end time to insert all tasks into NoVoHT
	timespec diff = timediff(start_tasks, end_tasks); // Measure the total time to insert all tasks into NoVoHT
	cout << num_tasks << " tasks inserted into NoVoHT" <<  endl;
	cout << "TIME TAKEN: " << diff.tv_sec << "  SECONDS  " << diff.tv_nsec << "  NANOSECONDS" << endl;
	if (client_logfile.is_open() && cl_LOGGING) {
		client_logfile << num_tasks << "tasks inserted into NoVoHT" <<  endl;
		client_logfile << "TIME TAKEN: " << diff.tv_sec << "  SECONDS  " << diff.tv_nsec << "  NANOSECONDS" << endl;
	}
	//exit(1);
	// Some temp parameters
	int num_packages = 0;
	int total_submitted1 = 0;
	static int id = 0;
	// Measure the start time for task submission into Wait queue
	clock_gettime(CLOCK_REALTIME, &start_tasks);
//	TaskDAG::iterator it = dag.begin();
//	while (total_submitted1 != num_tasks) {
//		Package package; string alltasks;
//		package.set_virtualpath(client_id); // Here key is just the client ID
//		package.set_operation(21);
//		//package.set_operation(22);
//		num_packages++;
//
//		int num_tasks_this_package = max_tasks_per_package;
//		int num_tasks_left = num_tasks - total_submitted1;
//		if (num_tasks_left < max_tasks_per_package) {
//			num_tasks_this_package = num_tasks_left;
//		}
//		for(int j = 0; j < num_tasks_this_package; j++) {
//			int task_id = it->first; ++it;
//
//        	        stringstream task_id_ss;
//                	task_id_ss << task_id << client_id; // Task ID + Client ID
//			alltasks.append(task_id_ss.str()); alltasks.append("\'\""); // Task ID
//		}
//		total_submitted1 = total_submitted1 + num_tasks_this_package;
//		package.set_realfullpath(alltasks);
//		string str = package.SerializeAsString();
//		//cout << "String size = " << str.size() << " str length = " << strlen(str.c_str());
//		int32_t ret = clientRet.svrtosvr(str, str.length(), toserver);
//                //int32_t ret = clientRet.svrtosvr(str, str.length(), selfindex);
//	}
	cout << "Before submitting to ZHT!" << endl;
	get_map_1(task_str_list, num_worker);
	cout << "continue" << endl;
	submittaskszht(clientRet, client_id);
	cout << "\tTotal Jobs submitted = " << num_tasks << endl;
	clock_gettime(CLOCK_REALTIME, &end_tasks); // Measure the end time to insert all tasks into Wait queue
	diff = timediff(start_tasks, end_tasks); // Measure the total time to insert all tasks into Wait queue
	//cout << "TIME TAKEN: " << diff.tv_sec << "  SECONDS  " << diff.tv_nsec << "  NANOSECONDS" << endl;
	if (client_logfile.is_open() && cl_LOGGING) {
		client_logfile << "to server = " << toserver << endl;
		client_logfile << "Total Jobs submitted = " << total_submitted1 << endl;
		client_logfile << "TIME TAKEN: " << diff.tv_sec << "  SECONDS  " << diff.tv_nsec << "  NANOSECONDS" << endl;
	}
	//exit(1);
}