int main(void) { int i; shmem_init(); npes = shmem_n_pes(); me = shmem_my_pe(); for (i = 0; i < DST_SIZE; i++) { dst[i] = -1; } for (i = 0; i < SHMEM_COLLECT_SYNC_SIZE; i += 1) { pSync[i] = SHMEM_SYNC_VALUE; } shmem_barrier_all(); shmem_fcollect64(dst, src, 2, 0, 0, npes, pSync); shmem_barrier_all(); show_dst("AFTER"); shmem_finalize(); return 0; }
int main (void) { int i; start_pes (0); npes = shmem_n_pes (); me = shmem_my_pe (); for (i = 0; i < DST_SIZE; i++) { dst[i] = -1; } for (i = 0; i < _SHMEM_BCAST_SYNC_SIZE; i += 1) { pSync[i] = _SHMEM_SYNC_VALUE; } shmem_barrier_all (); shmem_collect64 (dst, src, me + 1, 0, 0, 4, pSync); show_dst ("AFTER"); return 0; }
void mr_client_event_handler(mr_client_state * s, tw_bf * bf, mr_client_message * msg, tw_lp * lp) { int rand_result, i; tw_lpid dest_lp; tw_stime ts; tw_event *e; mr_client_message *m; //event_logging(s, msg, lp); //event_logging_f(s, msg, lp); switch(msg->msg_core.type) { case VS_MR_CLIENT_SUBMIT_JOB: { printf("Msg received at VS_MR_CLIENT_SUBMIT_JOB\n"); e = tw_event_new(s->job_tracker_id, tw_rand_exponential(lp->rng, 10), lp); m = tw_event_data(e); m->msg_core = msg->msg_core; m->msg_core.type = VS_MR_SERVER_JOB_REGISTRATION; push_src( &m->msg_core, &lp->gid); //show_src( &m->msg_core); tw_event_send(e); break; } case VS_MR_CLIENT_SUBMIT_JOB_SUCCESS: { e = tw_event_new(s->job_tracker_id, tw_rand_exponential(lp->rng, 10), lp); m = tw_event_data(e); m->msg_core.type = VS_MR_SERVER_JOB_REGISTRATION; printf("Job registration success from client %d and job id is %d\n",lp->gid,msg->job_ID); //show_src( &msg->msg_core); //tw_event_send(e); break; } case VS_MR_CLIENT_WRITE_START: { pop_dst(&msg->msg_core,&dest_lp); e = tw_event_new(dest_lp, 10, lp); m = tw_event_data(e); m->msg_core = msg->msg_core; m->msg_core.type = VS_MR_CLIENT_WRITE_SET_UP; tw_event_send(e); break; } case VS_MR_CLIENT_WRITE_SET_UP: { // name node gid is after client gid // This message is received at Name Node if (lp->gid == s->namenode_id) { s->NN_timer = max(s->NN_timer, tw_now(lp)); s->NN_timer += NN_process_time; e = tw_event_new(msg->msg_core.src_pid[0], s->NN_timer, lp); m = tw_event_data(e); m->msg_core = msg->msg_core; m->msg_core.src_pid[0] = lp->gid; m->msg_core.type = VS_MR_CLIENT_WRITE_SET_UP_ACK; tw_event_send(e); } else printf("\tMessage is not at name node, Please check!\n"); break; } case VS_MR_CLIENT_WRITE_SET_UP_ACK: { e = tw_event_new(lp->gid, tw_rand_exponential(lp->rng, WRITE_SET_UP_PREP_TIME), lp); m = tw_event_data(e); m->msg_core = msg->msg_core; //m->msg_core.type = VS_MR_CLIENT_WRITE_DATA_SEND; m->msg_core.type = VS_MR_CLIENT_WRITE_SOCKET_SET_UP; //pack dst data nodes ID to packet prep_src(&m->msg_core); prep_dst(&m->msg_core); //show_dst(&m->msg_core); for (i=0;i<N_REPLICA;i++) push_dst(&m->msg_core,&s->data_node_ID[i]); show_dst(&m->msg_core); //pop_dst(&m->msg_core,&dest_lp); //m->msg_core.replica_counter++; tw_event_send(e); break; } case VS_MR_CLIENT_WRITE_SOCKET_SET_UP: { // if message still hasn't reached the deepest point in the path // printf("msg->msg_core.replica_counter is %d\n",msg->msg_core.replica_counter); if (msg->msg_core.replica_counter<N_REPLICA) { pop_dst(&(msg->msg_core),&dest_lp); msg->msg_core.replica_counter++; push_src(&(msg->msg_core),&lp->gid); e = tw_event_new(dest_lp, tw_rand_exponential(lp->rng, WRITE_SET_UP_PREP_TIME), lp); m = tw_event_data(e); m->msg_core = msg->msg_core; m->msg_core.type = VS_MR_CLIENT_WRITE_SOCKET_SET_UP; tw_event_send(e); //printf("Appear in LP %d\n",lp->gid); } else { msg->msg_core.replica_counter--; pop_src(&(msg->msg_core),&dest_lp); e = tw_event_new(dest_lp, tw_rand_exponential(lp->rng, WRITE_SET_UP_PREP_TIME), lp); m = tw_event_data(e); m->msg_core = msg->msg_core; m->msg_core.type = VS_MR_CLIENT_WRITE_SOCKET_SET_UP_ACK; tw_event_send(e); } break; } case VS_MR_CLIENT_WRITE_SOCKET_SET_UP_ACK: { if (msg->msg_core.replica_counter==0) { e = tw_event_new(lp->gid, tw_rand_exponential(lp->rng, WRITE_SET_UP_PREP_TIME), lp); m = tw_event_data(e); m->msg_core = msg->msg_core; m->msg_core.type = VS_MR_CLIENT_WRITE_DATA_SEND; tw_event_send(e); //printf("LP %d Appear\n",lp->gid); } else { msg->msg_core.replica_counter--; pop_src(&(msg->msg_core),&dest_lp); e = tw_event_new(dest_lp, tw_rand_exponential(lp->rng, WRITE_SET_UP_PREP_TIME), lp); m = tw_event_data(e); m->msg_core = msg->msg_core; m->msg_core.type = VS_MR_CLIENT_WRITE_SOCKET_SET_UP_ACK; tw_event_send(e); } break; } case VS_MR_CLIENT_WRITE_DATA_SEND: { if (s->pkt_send_counter < Write_Request_size/Pkt_size) { // split request to packet s->pkt_send_counter++; e = tw_event_new(lp->gid, Pkt_size/Buffer_Copy_rate, lp); m = tw_event_data(e); m->msg_core = msg->msg_core; m->msg_core.type = VS_MR_CLIENT_WRITE_DATA_SEND; tw_event_send(e); // each packet corresponds to a real send // pick random data node e = tw_event_new(s->data_node_ID[0], Pkt_size/Buffer_Copy_rate, lp); m = tw_event_data(e); m->msg_core = msg->msg_core; m->msg_core.type = VS_MR_CLIENT_WRITE_DATA_SEND_ACK; m->msg_core.src_pid[0] = lp->gid; tw_event_send(e); } break; } case VS_MR_CLIENT_WRITE_DATA_SEND_ACK: { // split request to packet e = tw_event_new(msg->msg_core.src_pid[0], Pkt_size/Buffer_Copy_rate, lp); m = tw_event_data(e); m->msg_core = msg->msg_core; m->msg_core.type = VS_MR_CLIENT_WRITE_DONE; tw_event_send(e); break; } case VS_MR_CLIENT_WRITE_DONE: { s->pkt_recv_counter++; if ( s->pkt_recv_counter == Write_Request_size/Pkt_size ) { // send success msg to NN e = tw_event_new(s->namenode_id, CLOSE_TIME, lp); m = tw_event_data(e); m->msg_core = msg->msg_core; push_src(&(m->msg_core),&lp->gid); m->msg_core.type = VS_MR_CLIENT_WRITE_CLOSE; tw_event_send(e); } else printf("\tMessage is not at name node, Please check!\n"); break; } case VS_MR_CLIENT_WRITE_CLOSE: { //printf("Close finished at %d\n",lp->gid); // This message is received at Name Node if (lp->gid == s->namenode_id) { pop_src(&(msg->msg_core),&dest_lp); e = tw_event_new(dest_lp, CLOSE_TIME, lp); m = tw_event_data(e); m->msg_core = msg->msg_core; m->msg_core.type = VS_MR_CLIENT_WRITE_CLOSE_ACK; tw_event_send(e); } break; } case VS_MR_CLIENT_WRITE_CLOSE_ACK: { printf("Close finished at %d\n",lp->gid); /* e = tw_event_new(msg_core.src_pid[0], CLOSE_TIME, lp); */ /* m = tw_event_data(e); */ /* m->msg_core = msg->msg_core; */ //m->msg_core.type = VS_MR_CLIENT_WRITE_CLOSE_ACK; //tw_event_send(e); break; } } }