Esempio n. 1
0
static void send_scheduler_task (enum phase_e phase, size_t wid)
{
    size_t tid = user.scheduler_f (phase, wid);

    if (tid == NONE)
    {
	return;
    }

    enum task_type_e task_type = get_task_type (phase, tid, wid);
    size_t	     sid = NONE;

    if (task_type == LOCAL || task_type == LOCAL_SPEC)
    {
	sid = wid;
    }
    else if (task_type == REMOTE || task_type == REMOTE_SPEC)
    {
	sid = find_random_chunk_owner (tid);
    }

    XBT_INFO ("%s %zu assigned to %s %s", (phase==MAP?"map":"reduce"), tid,
	    MSG_host_get_name (config.workers[wid]),
	    task_type_string (task_type));

    send_task (phase, tid, sid, wid);

    update_stats (task_type);
}
Esempio n. 2
0
int client (int argc, char * argv[]) {
	//printf("starting client\n");
	int i;
	unsigned long int id;
	char myMailbox[MAILBOX_SIZE];
	char primary[MAILBOX_SIZE]; // when we use the decentrlized solution, the client send its request to the first-primary. (However the code is the same, we just change in the xml file the identity of the primary by the identity of the first-primary)

	if (argc != 3) {
		//printf("here in the client\n");
		exit(1);
	}

	id = atoi(argv[1]);
	sprintf(myMailbox, "client-%ld", id);
	// the name of the primary is known by the client
	strcpy(primary, argv[2]);

	srand(time(NULL) * id + MSG_get_clock());

	for (i = 0; i < nb_requests; i++) {
		MSG_process_sleep(((double)(rand () % 1000001)) / 1000.0);
		
		//send a request to the primary
		send_task(i, primary, myMailbox);		

		// wait for the result of the request before sending an other one
		receive_answer(myMailbox);
	}
	
	// signal to the primary that there is no more tasks to treat for that client
	//printf("%s: I send finalize\n", myMailbox);
	send_finalize(primary);

	return 0;
}
Esempio n. 3
0
      /** @brief helper function to send task */
      int process_send_call(reg_s * reg, process_descriptor_t * proc, process_descriptor_t * remote_proc, void * data)
      {
      XBT_DEBUG("Entering process_send_call");
      if (socket_registered(proc, (int) reg->arg[0]) != -1) { 
      if (!socket_netlink(proc, (int) reg->arg[0])) {
      XBT_DEBUG("%d This is not a netlink socket", (int) reg->arg[0]);
      //   compute_computation_time(proc);   // cree la computation task
      struct infos_socket *is = get_infos_socket(proc, (int) reg->arg[0]);
      struct infos_socket *s = comm_get_peer(is);
      is->ref_nb++;
      s->ref_nb++;

      XBT_DEBUG("%d->%d", (int) reg->arg[0], (int) reg->ret);
      XBT_DEBUG("Sending data(%d) on socket %d", (int) reg->ret, s->fd.fd);
      handle_new_send(reg, is, data);

      msg_task_t task = create_send_communication_task(proc, is, (int) reg->ret, proc->host, s->fd.proc->host);
      XBT_DEBUG("hosts: %s send to %s (size: %d)", MSG_host_get_name(proc->host), MSG_host_get_name(s->fd.proc->host),
	(int) reg->ret);


      MSG_task_set_bytes_amount(task, (int) reg->ret);
      MSG_task_set_data(task, data);

      send_task(s->fd.proc->host, task);

      is->ref_nb--;
      s->ref_nb--;
      return 1;
    }
      return 0;
    } else
	xbt_die("The socket is not registered");
      return 0;
    }
Esempio n. 4
0
 int send_next() {
    int q=0;
    while(true == task_list[q].sent && q < n_tasks) { 
       q++;
    }
    if (500 == q) {
       throw_error("No task");
       return -1;
    }
    debugMark(1);
    send_task(this_comm, task_list[q].task_msg[0],
                         task_list[q].task_msg[1],
                         task_list[q].task_msg[2]);
    debugMark(2);
    task_list[q].sent = true;
    last_sent = q;
    return q; 
 }
Esempio n. 5
0
int main(int argv,char**argc){
	key_t key;
	mymsg msg;
	int clients[100];
	int index = 0;
	srand(time(NULL));

	signal(SIGINT,sig_handle);

	//client->server queue creation arg[0]-path arg[1]-proj_id
    if((key = ftok(argc[1], atoi(argc[2])))==-1){
    	perror("Key error");
		exit(1);
    }

	if((csqid = msgget(key, ALL_PERM|IPC_CREAT))==-1){
		perror("Creating queue error");
		exit(1);
	}
	
	while(1){
		//Get messege from client
		if(msgrcv(csqid, &msg, MSG_SIZE, 0, MSG_NOERROR)==-1){
			perror("Receiving error");
			exit(1);
		}
		//Client wants to register
		if(msg.mtype==CL_REG){
			if(index<100)
				register_client(clients,&index,&msg);
		}
		//Client ready for task
		else if(msg.mtype==CL_RED){
			send_task(clients,&msg);
		}
		//Client sends result
		else if(msg.mtype==CL_RES){
			print_result(&msg);
		}
	}

	return 0;
}
Esempio n. 6
0
int main(int argc, char ** argv){
    TAILQ_INIT(&head);
    int nproc, numt, i, nhost, narch;
    int num_tasks = 0;
    struct pvmhostinfo *hostp;
    struct stat s;
    FILE * codefile = fopen("./codes", "w");

    if(argc != 2){
        exit_prog("USAGE: ./taskgen directory\n",1);
    }
    else {
        stat(argv[1], &s);
        if(s.st_mode & S_IFDIR){
            char path[PATH_MAX+1];
            realpath(argv[1],path);
            printf("Loading graphs from %s...", path);
            fflush(stdout);
            load_graph_dir(path, &num_tasks);
            printf("done. Found %d tasks.\n", num_tasks);
        }
        else{
            printf("%s is not a directory. Please check arguments.\n", argv[1]);
            exit_prog(NULL, 1);
        }
    }

    pvm_config(&nhost, &narch, &hostp);                         /*Set number of slaves to start */
    nproc = nhost * 3;                                          /*3 processes per host */

    printf("Spawning %d worker tasks on %d machines...", nproc, nhost);

    int tids[nproc];                                            /*hold the task ids of the workers */

    int flags = PvmTaskDefault;
   // flags += PvmTaskDebug;

    numt =pvm_spawn("worker", (char**)0, flags, "", nproc, tids);   /*start up the workers */

    if(numt < nproc){                                           /*Error Checking */
        printf("\n Trouble spawing slaves. Error codes are:\n");
        for(i = numt; i < nproc; i++){
            printf("TID %d: %d\n", i, tids[i]);
        }
        for(i = 0; i < numt; i++){
            pvm_kill(tids[i]);
        }
        exit_prog("Failure.\n",1);
    }
    printf("done. Connected.\n");
    
    /* Main loop */
    int bufid, bytes, msgtype, source;
    int sent_tasks, comp_tasks, found_codes = 0;
    int finished = 0;
    int percent_comp = 0;
    char * buf;
    while(!finished){    
        bufid = pvm_recv(-1, -1);                               /*Accept any message from any task BLOCKING CALL*/
        pvm_bufinfo(bufid, &bytes, &msgtype, &source);
        switch(msgtype){
            case MSGREQTASK:
                if(!TAILQ_EMPTY(&head)){
                    send_task(source);                              /*send out the message */
                    sent_tasks++;
                }
                break;
            case MSGCODE:
                buf = malloc(bytes);
                pvm_upkstr(buf);
                fprintf(codefile, "%s\n", buf);
                fflush(codefile);
                comp_tasks++;
                found_codes++;
                break;
            case MSGNOCODE:
                comp_tasks++;
                break;
            default:
                printf("Incorrect MSGTYPE received from task %d. Received: %d\n", source, msgtype);
                break;
            }
        
        if(((float)comp_tasks/num_tasks * 100) > percent_comp + 1){
                printf("Tasks Complete: %d    Tasks Sent: %d    Percent Complete: %.2f\n", 
                comp_tasks, sent_tasks, (float)comp_tasks/num_tasks * 100);
                percent_comp = (float)comp_tasks/num_tasks * 100;
        }
    
        if(comp_tasks == num_tasks){
            finished = 1;
        }
        
    }
 
    printf("All tasks complete.\n");

    exit_prog(NULL, 0);
    return 0;
}