static void allreduce_imp(const struct comm *com, gs_dom dom, gs_op op, void *v, uint vn, void *buf) { size_t total_size = vn*gs_dom_size[dom]; const uint id=com->id, np=com->np; uint n = np, c=1, odd=0, base=0; while(n>1) { odd=(odd<<1)|(n&1); c<<=1, n>>=1; if(id>=base+n) c|=1, base+=n, n+=(odd&1); } while(n<np) { if(c&1) n-=(odd&1), base-=n; c>>=1, n<<=1, n+=(odd&1); odd>>=1; if(base==id) { comm_recv(com, buf,total_size, id+n/2,id+n/2); gs_gather_array(v,buf,vn, dom,op); } else { comm_send(com, v,total_size, base,id); break; } } while(n>1) { if(base==id) comm_send(com, v,total_size, id+n/2,id); else comm_recv(com, v,total_size, base,base); odd=(odd<<1)|(n&1); c<<=1, n>>=1; if(id>=base+n) c|=1, base+=n, n+=(odd&1); } }
/* * int * slave_fd_probe(int sock); * ------------------------- * Probe the slave at the other end of 'sock'. * * Mandatory params: sock * Optional params : * * Return values: * -1 Error * 0 Success */ int slave_fd_probe(int sock){ // Local variables synexec_msg_t net_msg; // synexec msg int err = 0; // Return code // Probe the slave if (comm_send(sock, MT_SYNEXEC_MSG_PROBE, NULL, NULL, 0) <= 0){ goto err; } // Process the reply if (comm_recv(sock, &net_msg, NULL, NULL, NULL) <= 0){ goto err; } if (net_msg.command != MT_SYNEXEC_MSG_REPLY){ goto err; } out: // Return return(err); err: err = -1; goto out; }
/** * * * @author Francesco Quaglia */ int messages_checking(void) { msg_t msg; int at_least_one_message = 0; // Are we in GVT computation phase? // TODO a cosa serve questa parte qui sotto?! // if (ComputingGvt() == false) // send_forced_ack(); // Check whether we have received any ack message receive_ack(); // If we have pending messages, we process all of them in order to update the queues while(pending_msg()){ at_least_one_message = 1; // Receive the message (void)comm_recv((char*)&msg, sizeof(msg_t), MPI_CHAR, MPI_ANY_SOURCE, MSG_EVENT, MPI_COMM_WORLD, MPI_STATUS_IGNORE); // For GVT Operations gvt_messages_rcvd[GidToKernel(msg.sender)] += 1; // Update the queues // DataUpdating(&msg); } // Did we receive at least one message? return at_least_one_message; }
int oemp_ReceiveCmdOrAck(WORD wDevID, WORD* pwCmdOrAck, int* pnParam) { SB_OEM_PKT pkt; int nReceivedBytes; if ((pwCmdOrAck == NULL) || (pnParam == NULL)) { return PKT_PARAM_ERR; } nReceivedBytes = comm_recv((BYTE*)&pkt, SB_OEM_PKT_SIZE, gCommTimeOut); if (nReceivedBytes != SB_OEM_PKT_SIZE) return PKT_COMM_ERR; if ((pkt.Head1 != STX1) || (pkt.Head2 != STX2)) { return PKT_HDR_ERR; } if (pkt.wDevId != wDevID) return PKT_DEV_ID_ERR; if (pkt.wChkSum != oemp_CalcChkSumOfCmdAckPkt(&pkt)) return PKT_CHK_SUM_ERR; *pwCmdOrAck = pkt.wCmd; *pnParam = pkt.nParam; return 0; }
int lewp() { struct pollfd pfd[2]; static char buffer[MAX_LINE_LEN], *nl; int nread; pfd[0].fd = fd_input; pfd[1].fd = fd_cmd; pfd[0].events = pfd[1].events = POLLIN; while(!finito){ if(comm_recv(&commt, &commcallback)){ outputf(file_err, "comm_recv() failed: %s\n", comm_lasterr(&commt)); return 1; } switch(poll(pfd, 2, FIFO_POLL_WAIT)){ case 0: /* notan happan */ continue; case -1: perrorf("%s", "poll()"); return 1; } #define READ(fd) \ nread = read(fd, buffer, MAX_LINE_LEN); \ \ switch(nread){ \ case -1: \ perrorf("%s", "read()"); \ return 1; \ case 0: \ break; \ default: \ buffer[nread-1] = '\0'; \ if((nl = strchr(buffer, '\n'))) \ *nl = '\0'; \ } #define BIT(x, b) (((x) & (b)) == (b)) if(BIT(pfd[0].revents, POLLIN)){ READ(pfd[0].fd); if(nread > 0) /* message */ comm_sendmessage(&commt, buffer); } if(BIT(pfd[1].revents, POLLIN)){ READ(pfd[1].fd); if(nread > 0) proc_cmd(buffer); } } return 0; }
static mlabel* plan_from_rib(mesh* m, unsigned n, rcopy idx[]) { mlabel* plan; unsigned i; plan = migration_plan_new(m); for (i = 0; i < n; ++i) pack_remote(idx[i]); comm_exch(); while (comm_recv()) mlabel_set(plan, unpack_local(mesh_elem(m)), comm_from()); return plan; }
/* update local objects (shrapnells,extras,explosions...) and communicate * every client_comm_delay seconds either with real or fake server */ static void update_game( int ms ) { int i; /* run the fake server game */ if ( game->game_type == GT_LOCAL ) { game_set_current( local_game ); game_update( ms ); game_set_current( game ); } /* local animations and movements */ for ( i = 0; i < game->paddle_count; i++ ) client_paddle_update( game->paddles[i], ms ); client_shots_update( ms ); client_balls_update( ms ); client_extras_update( ms ); client_walls_update( ms ); shrapnells_update( ms ); frame_warp_icon_update( ms ); shine_update( ms ); exps_update( ms ); displays_update( ms ); credit_update( ms ); /* communicate */ if ( (no_comm_since+=ms) >= client_comm_delay ) { no_comm_since -= client_comm_delay; /* send paddle state */ comm_send_paddle( l_paddle ); /* receive game data from local or remote server and * apply it to the game context. */ comm_recv(); /* update score displays */ if (!showing_best) display_set_value( display_score[0], game->paddles[0]->player->stats.total_score + game->paddles[0]->score ); if ( game->game_type == GT_NETWORK ) display_set_value( display_score[1], game->paddles[1]->player->stats.total_score + game->paddles[1]->score ); /* update bonus level information */ if (bl_display) update_bonus_level_display(); } }
static void scan_imp(void *scan, const struct comm *com, gs_dom dom, gs_op op, const void *v, uint vn, void *buffer) { comm_req req[2]; size_t vsize = vn*gs_dom_size[dom]; const uint id=com->id, np=com->np; uint n = np, c=1, odd=0, base=0; void *buf[2]; void *red = (char*)scan+vsize; buf[0]=buffer,buf[1]=(char*)buffer+vsize; while(n>1) { odd=(odd<<1)|(n&1); c<<=1, n>>=1; if(id>=base+n) c|=1, base+=n, n+=(odd&1); } gs_init_array(scan,vn,dom,op); memcpy(red,v,vsize); while(n<np) { if(c&1) n-=(odd&1), base-=n; c>>=1, n<<=1, n+=(odd&1); odd>>=1; if(base==id) { comm_irecv(&req[0],com, buf[0],vsize, id+n/2,id+n/2); comm_isend(&req[1],com, red ,vsize, id+n/2,id); comm_wait(req,2); gs_gather_array(red,buf[0],vn,dom,op); } else { comm_irecv(&req[0],com, scan,vsize, base,base); comm_isend(&req[1],com, red ,vsize, base,id); comm_wait(req,2); break; } } while(n>1) { if(base==id) { comm_send(com, scan ,2*vsize, id+n/2,id); } else { comm_recv(com, buffer,2*vsize, base,base); gs_gather_array(scan,buf[0],vn,dom,op); memcpy(red,buf[1],vsize); } odd=(odd<<1)|(n&1); c<<=1, n>>=1; if(id>=base+n) c|=1, base+=n, n+=(odd&1); } }
int oemp_ReceiveData( WORD wDevID, BYTE* pBuf, int nSize ) { WORD wReceivedChkSum, wChkSum; BYTE Buf[4],*pCommBuf; int nReceivedBytes; if( pBuf == NULL ) return PKT_PARAM_ERR; pCommBuf = new BYTE[nSize+SB_OEM_HEADER_SIZE+SB_OEM_DEV_ID_SIZE+SB_OEM_CHK_SUM_SIZE]; nReceivedBytes = comm_recv( pCommBuf, nSize+SB_OEM_HEADER_SIZE+SB_OEM_DEV_ID_SIZE+SB_OEM_CHK_SUM_SIZE, gCommTimeOut ); if( nReceivedBytes != nSize+SB_OEM_HEADER_SIZE+SB_OEM_DEV_ID_SIZE+SB_OEM_CHK_SUM_SIZE ) { if(pCommBuf) delete pCommBuf; return PKT_COMM_ERR; } memcpy(Buf, pCommBuf, SB_OEM_HEADER_SIZE+SB_OEM_DEV_ID_SIZE); memcpy(pBuf, pCommBuf+SB_OEM_HEADER_SIZE+SB_OEM_DEV_ID_SIZE, nSize); wReceivedChkSum = *(WORD*)(pCommBuf+nSize+SB_OEM_HEADER_SIZE+SB_OEM_DEV_ID_SIZE); if(pCommBuf) delete pCommBuf; ////////////// pc end /////////////// if( ( Buf[0] != STX3 ) || ( Buf[1] != STX4 ) ) { return PKT_HDR_ERR; } if( *((WORD*)(&Buf[SB_OEM_HEADER_SIZE])) != wDevID ) return PKT_DEV_ID_ERR; wChkSum = oemp_CalcChkSumOfDataPkt( Buf, SB_OEM_HEADER_SIZE+SB_OEM_DEV_ID_SIZE ); wChkSum += oemp_CalcChkSumOfDataPkt( pBuf, nSize ); if( wChkSum != wReceivedChkSum ) return PKT_CHK_SUM_ERR; return 0; }
/* * static int * config_slave(slave_t *slave, char *conf_ptr, off_t conf_len); * ------------------------------------------------------------- * This function sends the session configuration file to 'slave' and confirms * that he is happy with the contents. * * Mandatory params: slave, conf_ptr * Optional params : * * Return values: * -1 Error * 0 Success */ static int config_slave(slave_t *slave, char *conf_ptr, off_t conf_len){ // Local variables synexec_msg_t net_msg; // Synexec msg int err = 0; // Return code // Send configuration to slave if (comm_send(slave->slave_fd, MT_SYNEXEC_MSG_CONF, NULL, conf_ptr, conf_len) < 0){ goto err; } if (verbose > 0){ printf("%s: Configuration sent to slave (%s:%hu).\n", __FUNCTION__, inet_ntoa(slave->slave_addr.sin_addr), ntohs(slave->slave_addr.sin_port)); fflush(stdout); } // Await reply if (comm_recv(slave->slave_fd, &net_msg, NULL, NULL, NULL) < 0){ goto err; } if (net_msg.command != MT_SYNEXEC_MSG_CONF_OK){ fprintf(stderr, "%s: Slave (%s:%hu) refused configuration file.\n", __FUNCTION__, inet_ntoa(slave->slave_addr.sin_addr), ntohs(slave->slave_addr.sin_port)); goto err; } if (verbose > 0){ printf("%s: Configuration OK from slave (%s:%hu).\n", __FUNCTION__, inet_ntoa(slave->slave_addr.sin_addr), ntohs(slave->slave_addr.sin_port)); fflush(stdout); } out: // Return return(err); err: err = -1; goto out; }
int main() { COMM_ERR comm_status; int len = BUFFER_LEN; board_init(); comm_init(); comm_send(":SSBOOT", 7); comm_status = comm_recv(buf, &len, BOOT_TIMEOUT_MS); if (comm_status == COMM_ERR_TIMEOUT || buf[0] != 'i') { comm_send("NOK", 3); while(1); } comm_send("OK", 2); while(1); return 0; }
/* * static int * comm_tcp_accept(int sock, struct timeval *timeout, slaveset_t *slaveset); * ------------------------------------------------------------------------- * This function accepts TCP connections from slaves and inserts them into * 'slaveset'. * * Mandatory params: sock, slaveset * Optional params : timeout * * NOTES: * If 'timeout' is not specified, the function may wait forever. * * Return values: * -1: Error * 0: Timeout while waiting * 1: One slave added */ static int comm_tcp_accept(int sock, struct timeval *timeout, slaveset_t *slaveset){ // Local variables fd_set fds; // Select fd_set int slave_sock = -1; // Socket to accept new slaves struct sockaddr_in slave_addr; // Slave's address socklen_t slave_len; // Address length synexec_msg_t net_msg; // synexec msg int err = 0; // Return code // Wait until there is something to read FD_ZERO(&fds); FD_SET(sock, &fds); err = select(sock+1, &fds, NULL, NULL, timeout); if (err == -1){ perror("select"); fprintf(stderr, "%s: Error waiting to receive response from slaves.\n", __FUNCTION__); goto out; }else if (err == 0){ goto out; } // There is a connection on the pipe slave_len = sizeof(slave_addr); if ((slave_sock = accept(sock, (struct sockaddr *)&slave_addr, &slave_len)) < 0){ perror("accept"); fprintf(stderr, "%s: Error accepting new connection.\n", __FUNCTION__); goto err; } if (verbose > 0){ printf("%s: Accepted connection from '%s:%hu'.\n", __FUNCTION__, inet_ntoa(slave_addr.sin_addr), ntohs(slave_addr.sin_port)); fflush(stdout); } // Process hello if (comm_recv(slave_sock, &net_msg, NULL, NULL, NULL) <= 0){ (void)close(slave_sock); err = 0; goto out; } if (net_msg.command != MT_SYNEXEC_MSG_REPLY){ (void)close(slave_sock); err = 0; goto out; } // Add the connection to the slaveset err = slave_add(slaveset, &slave_addr, slave_sock); if (err && (verbose > 1)){ printf("%s: Added slave: %s:%hu (%d).\n", __FUNCTION__, inet_ntoa(slave_addr.sin_addr), ntohs(slave_addr.sin_port), slave_sock); fflush(stdout); } out: // Return return(err); err: err = -1; goto out; }
/* * int * join_slaves(slaveset_t *slaveset); * ---------------------------------- * This function keep track of the slaves that are executing, waiting for * them to finish their work and return the time values. * * Mandatory params: slaveset * Optional params : * * Return values: * -1 Error * 0 Success */ int join_slaves(slaveset_t *slaveset){ // Local variables fd_set fds; // Select fd_set int mfd; // Largest fd synexec_msg_t net_msg; // Synexec msg char *data; // Transfer buffer int i; // Temporary integer slave_t *slave = NULL; // Temporary slave int err = 0; // Return code // Loop until all slaves have finished do { // Set all slaves into the fd_set FD_ZERO(&fds); mfd = -1; slave = slaveset->slave; while(slave){ if (!memcmp(&(slave->slave_time[2]), &(slave->slave_time[1]), sizeof(slave->slave_time[2]))){ FD_SET(slave->slave_fd, &fds); if (slave->slave_fd > mfd){ mfd = slave->slave_fd; } } slave = slave->next; } if (mfd == -1){ // All slaves in set have completed goto out; } // Check which slaves have something to say // TODO: This should timeout and then I need to probe the slaves i = select(mfd+1, &fds, NULL, NULL, NULL); if (i <= 0){ perror("select"); goto err; } slave = slaveset->slave; while(slave){ if (FD_ISSET(slave->slave_fd, &fds)){ // Read from this slave data = NULL; i = comm_recv(slave->slave_fd, &net_msg, NULL, (void**)&data, NULL); if (i < 0) goto err; if ((i > 0) && (net_msg.command == MT_SYNEXEC_MSG_FINISHD)){ struct { int64_t tv_sec; int64_t tv_usec; } net_time[3]; if (net_msg.datalen != sizeof(net_time)){ fprintf(stderr, "%s: Wrong datalen for FINISHD (slave %s:%hu).\n", __FUNCTION__, inet_ntoa(slave->slave_addr.sin_addr), ntohs(slave->slave_addr.sin_port)); fflush(stderr); continue; } // Unmarshal data memcpy(net_time, data, sizeof(net_time)); slave->slave_time[0].tv_sec = net_time[0].tv_sec; slave->slave_time[0].tv_usec = net_time[0].tv_usec; slave->slave_time[1].tv_sec = net_time[1].tv_sec; slave->slave_time[1].tv_usec = net_time[1].tv_usec; slave->slave_time[2].tv_sec = net_time[2].tv_sec; slave->slave_time[2].tv_usec = net_time[2].tv_usec; printf("%s: Slave (%s:%hu) completed\n", __FUNCTION__, inet_ntoa(slave->slave_addr.sin_addr), ntohs(slave->slave_addr.sin_port)); fflush(stdout); } } slave = slave->next; } } while(1); out: // Return return(err); err: err = -1; goto out; }
/* run the state driven loop until game is broken up or finished */ void client_game_run( void ) { int ms, frame_delay = config.fps?10:1; int button_clicked, key_pressed; SDL_Event event; int abort = 0, i, j, penalty; /* frame rate */ int frames = 0; int frame_time = SDL_GetTicks(); event_clear_sdl_queue(); stk_display_fade( STK_FADE_IN, STK_FADE_DEFAULT_TIME ); stats_received = 0; stk_timer_reset(); ms = 1; while ( !abort && !stk_quit_request ) { /* check wether an event occured */ button_clicked = key_pressed = 0; if ( SDL_PollEvent( &event ) ) { if ( client_state == CS_PAUSE && game->game_type == GT_NETWORK ) gui_dispatch_event( &event, ms ); else if ( event.type == SDL_MOUSEBUTTONDOWN ) button_clicked = event.button.button; else if ( event.type == SDL_KEYDOWN ) { key_pressed = event.key.keysym.sym; if ( handle_default_key( key_pressed, &abort ) ) key_pressed = 0; } else if (event.type == SDL_ACTIVEEVENT) { if (event.active.state == SDL_APPINPUTFOCUS || event.active.state == SDL_APPACTIVE ) if (event.active.gain == 0 ) client_set_pause(1); } } else if ( client_state == CS_PAUSE && game->game_type == GT_NETWORK ) gui_dispatch_event( 0, ms ); /* check whether Shift is pressed to switch between own and highest score */ if (game->game_type == GT_LOCAL) handle_display_switch(); /* let server know we're still alive except * in CS_PLAY as we send paddle updates there */ if ( game->game_type == GT_NETWORK ) comm_send_heartbeat(); /* handle client */ switch ( client_state ) { case CS_FINAL_STATS: if ( key_pressed==SDLK_SPACE ) abort = 1; break; case CS_FATAL_ERROR: /* after game was violently broken up the server * may still send the stats of the game so far */ if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ set_state( CS_RECV_STATS ); display_text( font, "Receiving final stats..." ); } break; case CS_FINAL_TABLE: if ( button_clicked || key_pressed ) { check_highscores(); select_chart( game_set->name, 0 ); /* remove saved game */ slot_delete( 0 ); slot_update_hint( 0, item_resume_0->hint ); /* quit local game */ abort = 1; } break; case CS_SCORE_TABLE: /* show who's next player and scores in local game */ display_score_table( "Next Player: %s", cur_player->name ); set_state( CS_GET_READY ); break; case CS_BONUS_LEVEL_SCORE: /* display total score from this level for player */ display_bonus_level_score(); set_state( CS_GET_READY_FOR_NEXT_LEVEL ); break; case CS_FINAL_PLAYER_INFO: if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ set_state( CS_NEXT_PLAYER ); } break; case CS_RECV_LEVEL: comm_recv(); if ( cur_player->next_level_received ) { cur_player->next_level_received = 0; cur_player->paddle_id = cur_player->next_paddle_id; init_next_round(); } break; case CS_RECV_STATS: comm_recv(); if ( stats_received ) { set_state( CS_FINAL_STATS ); display_final_stats(); } break; case CS_ROUND_RESULT: if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ if ( game_over ) { set_state( CS_RECV_STATS ); display_text( font, "Receiving final stats..." ); } else { set_state( CS_RECV_LEVEL ); display_text( font, "Receiving level data..." ); } } break; case CS_GET_READY: if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ comm_send_short( MSG_READY ); set_state( CS_PLAY ); } break; case CS_GET_READY_FOR_NEXT_LEVEL: if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ set_state( CS_NEXT_LEVEL ); } break; case CS_PAUSE: if ( game->game_type == GT_LOCAL ) break; /* check wether pause chatroom has been closed * either by client or remote */ comm_recv(); break; case CS_PLAY: /* hide objects */ begin_frame(); /* apply events to local paddle */ paddle_handle_events( l_paddle, ms ); /* update local objects and communicate if * comm_delay ms have passed */ update_game( ms ); /* show objects */ end_frame(); /* handle local level over */ if ( game->level_over ) { if ( game->game_type == GT_LOCAL ) { if ( game_set == 0 ) { abort = 1; /* was a test level */ grab_input(0); break; } if ( game->winner == PADDLE_BOTTOM ) { if (local_game->isBonusLevel) set_state( CS_BONUS_LEVEL_SCORE ); else set_state( CS_NEXT_LEVEL ); } else set_state( CS_LOOSE_LIFE ); } else { finalize_round(); } } break; case CS_NEXT_LEVEL: /* apply paddle stats to player */ game_set_current( local_game ); game_update_stats( PADDLE_BOTTOM, &cur_player->stats ); game_set_current( game ); /* init next level for player in local game */ cur_player->level_id++; if ( cur_player->level_id >= game_set->count ) { /* deactivate player */ cur_player->lives = 0; display_text( font, "You've cleared all levels...#Congratulations!!!" ); set_state( CS_FINAL_PLAYER_INFO ); break; } /* get snapshot for next init */ cur_player->snapshot = *game_set->levels[cur_player->level_id]; /* cycle players */ set_state( CS_NEXT_PLAYER ); break; case CS_RESTART_LEVEL: /* apply paddle stats to player */ game_set_current( local_game ); game_update_stats( PADDLE_BOTTOM, &cur_player->stats ); game_set_current( game ); /* reset level for next turn */ cur_player->snapshot = *game_set->levels[cur_player->level_id]; /* decrease lives (is checked that this wasn't the last one) */ cur_player->lives--; /* cycle players */ set_state( CS_NEXT_PLAYER ); break; case CS_LOOSE_LIFE: /* apply paddle stats to player */ game_set_current( local_game ); game_update_stats( PADDLE_BOTTOM, &cur_player->stats ); game_set_current( game ); /* remember level for next turn */ game_get_level_snapshot( &cur_player->snapshot ); /* decrease lives */ cur_player->lives--; if ( cur_player->lives == 0 ) { display_text( font, "You've lost all lives...#Do you want to buy a continue#for 100%% of your score? y/n" ); set_state( CS_CONFIRM_CONTINUE ); //set_state( CS_FINAL_PLAYER_INFO ); break; } set_state( CS_NEXT_PLAYER ); break; case CS_NEXT_PLAYER: /* game over? */ if ( players_count() == 0 ) { display_score_table( "Game Over!" ); set_state( CS_FINAL_TABLE ); break; } /* speak and fade */ play_speech(); fade_anims(); /* finalize current game context */ finalize_level(); /* set next player */ cur_player = players_get_next(); init_level( cur_player, PADDLE_BOTTOM ); if ( player_count > 1 ) set_state( CS_SCORE_TABLE ); else { set_state( CS_PLAY ); /* one player starts immediately */ stk_display_update( STK_UPDATE_ALL ); } break; case CS_CONFIRM_CONTINUE: case CS_CONFIRM_QUIT: case CS_CONFIRM_WARP: case CS_CONFIRM_RESTART: if ( key_pressed == 0 ) break; if ( key_pressed==SDLK_n||key_pressed==SDLK_ESCAPE ) { /* if denying continue... DIE!!! */ if ( client_state == CS_CONFIRM_CONTINUE ) { SDL_Delay(250); /* give time to release button */ set_state( CS_NEXT_PLAYER ); //set_state( CS_FINAL_PLAYER_INFO ); } else set_state( CS_PLAY ); break; } if ( key_pressed != SDLK_y && key_pressed != SDLK_z ) break; /* handle confirmed action */ SDL_Delay(250); /* give time to release button */ switch( client_state ) { case CS_CONFIRM_CONTINUE: /* clear score and give full lives again */ cur_player->lives = game->diff->lives; cur_player->stats.total_score = 0; set_state( CS_NEXT_PLAYER ); break; case CS_CONFIRM_QUIT: comm_send_short( MSG_QUIT_GAME ); if ( game->game_type == GT_LOCAL ) { /* apply paddle stats to player */ game_set_current( local_game ); game_update_stats( PADDLE_BOTTOM, &cur_player->stats ); game_set_current( game ); /* no higscore check anymore as game is supposed to * be resumed until normal game over */ /* testing levels don't got for * high scores *** if ( game_set ) { check_highscores(); select_chart( game_set->name, 0 ); }*/ /* save local game */ if ( game_set != 0 /*not testing a level*/ ) save_local_game( 0 ); abort = 1; } else { /* await game stats */ set_state( CS_RECV_STATS ); display_text( font, "Receiving final stats..." ); } break; case CS_CONFIRM_WARP: game->winner = -1; /* no speech */ local_game->winner = -1; /* not counted as win */ /* substract doubled score of remaining bricks */ penalty = 0; for ( i = 0; i < MAP_WIDTH; i++ ) for ( j = 0; j < MAP_HEIGHT; j++ ) if ( local_game->bricks[i][j].dur != -1 ) penalty += local_game->bricks[i][j].score; printf( "warp penalty: -%d\n", penalty ); local_game->paddles[0]->score -= penalty; set_state( CS_NEXT_LEVEL ); break; case CS_CONFIRM_RESTART: game->winner = -1; /* no speech */ local_game->winner = -1; /* not counted as win */ local_game->level_over = 1; set_state( CS_RESTART_LEVEL ); break; } break; } /* update anything that was changed */ stk_display_update( STK_UPDATE_RECTS ); /* get time since last call and delay if below frame_delay */ ms = stk_timer_get_time(); if ( ms < frame_delay ) { SDL_Delay( frame_delay - ms ); ms += stk_timer_get_time(); } frames++; } finalize_level(); client_state = CLIENT_NONE; stk_display_fade( STK_FADE_OUT, STK_FADE_DEFAULT_TIME ); if ( stk_quit_request ) comm_send_short( MSG_DISCONNECT ); else comm_send_short( MSG_UNHIDE ); /* frame rate */ frame_time = SDL_GetTicks() - frame_time; printf( "Time: %.2f, Frames: %i -> FPS: %.2f\n", (double)frame_time / 1000, frames, 1000.0*frames/frame_time ); event_clear_sdl_queue(); /* update the selected user and the user list in network as * we received ADD/REMOVE_USER messages */ gui_list_update( list_users, client_users->count ); /* re-select current entry */ if ( client_user ) { i = list_check( client_users, client_user ); if ( i != -1 ) gui_list_select( list_users, 0, i, 1 ); } }
static void partition(unsigned* n, point** o, rcopy** rc, plane mp) { unsigned pn; unsigned nn; point* po; point* no; rcopy* prc; rcopy* nrc; unsigned lin; unsigned long tin; unsigned lout; unsigned long tout; unsigned long in_i; unsigned long out_i; int rank_is_in; unsigned ranks_in; unsigned ranks_out; unsigned long quo; unsigned long rem; unsigned i; unsigned long dest_i; int dest_rank; unsigned rank, size; rank = (unsigned) comm_rank(); size = (unsigned) comm_size(); pn = *n; po = *o; prc = *rc; lin = count_local_in(pn, po, mp); lout = pn - lin; tin = mpi_add_ulong(comm_mpi(), lin); tout = mpi_add_ulong(comm_mpi(), lout); ranks_in = size / 2; rank_is_in = (rank < ranks_in); ranks_out = size - ranks_in; if (rank_is_in) { quo = tin / ranks_in; rem = tin % ranks_in; nn = (unsigned) quo; if (rank == ranks_in - 1) nn += (unsigned) rem; } else { quo = tout / ranks_out; rem = tout % ranks_out; nn = (unsigned) quo; if (rank - ranks_in == ranks_out - 1) nn += (unsigned) rem; } no = my_malloc(sizeof(point) * nn); nrc = my_malloc(sizeof(rcopy) * nn); in_i = mpi_exscan_ulong(comm_mpi(), lin); out_i = mpi_exscan_ulong(comm_mpi(), lout); for (i = 0; i < pn; ++i) { if (plane_has(mp, po[i])) { dest_i = in_i++; dest_rank = (int) (dest_i / quo); dest_rank = MIN(dest_rank, (int)ranks_in - 1); ASSERT(dest_rank < (int)ranks_in); } else { dest_i = out_i++; dest_rank = (int) (dest_i / quo); dest_rank += ranks_in; dest_rank = MIN(dest_rank, comm_size() - 1); ASSERT((dest_rank - (int)ranks_in) < (int)ranks_out); } COMM_PACK(dest_i, dest_rank); COMM_PACK(po[i], dest_rank); COMM_PACK(prc[i], dest_rank); } comm_exch(); while (comm_recv()) { COMM_UNPACK(dest_i); if (rank_is_in) i = (unsigned) (dest_i - (rank * quo)); else i = (unsigned) (dest_i - ((rank - ranks_in) * quo)); COMM_UNPACK(no[i]); ASSERT(plane_has(mp, no[i]) == rank_is_in); COMM_UNPACK(nrc[i]); } my_free(po); my_free(prc); *n = nn; *o = no; *rc = nrc; }