int main(int argc, char *argv[]) { int my_rank; double mpi_start_time, mpi_end_time; deme *subpop = (deme*) malloc(sizeof(deme)); MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); init_population(subpop, argc, argv); mpi_start_time = MPI_Wtime(); while (!subpop->complete) { migration(subpop); reproduction(subpop); crossover(subpop); mutation(subpop); fitness(subpop); subpop->old_pop = subpop->new_pop; subpop->cur_gen++; check_complete(subpop); sync_complete(subpop); report_all(subpop); } mpi_end_time = MPI_Wtime(); report_fittest(subpop); MPI_Finalize(); printf("[%i] Elapsed time: %f\n", my_rank, mpi_end_time - mpi_start_time); return 1; }
/** * Continuation to call the receive callback. * * @param cls our handle to the client connection * @param tc scheduler context */ static void receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CLIENT_Connection *client = cls; GNUNET_CLIENT_MessageHandler handler = client->receiver_handler; const struct GNUNET_MessageHeader *cmsg = (const struct GNUNET_MessageHeader *) client->received_buf; void *handler_cls = client->receiver_handler_cls; uint16_t msize = ntohs (cmsg->size); char mbuf[msize]; struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf; LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %u and size %u\n", ntohs (cmsg->type), msize); client->receive_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_assert (GNUNET_YES == client->msg_complete); GNUNET_assert (client->received_pos >= msize); memcpy (msg, cmsg, msize); memmove (client->received_buf, &client->received_buf[msize], client->received_pos - msize); client->received_pos -= msize; client->msg_complete = GNUNET_NO; client->receiver_handler = NULL; check_complete (client); if (NULL != handler) handler (handler_cls, msg); }
static void phase_one(void){ #line 1463 "ctangle.w" phase= 1; section_count= 0; reset_input(); skip_limbo(); while(!input_has_ended)scan_section(); check_complete(); phase= 2; }
void #line 350 "./cwebdir/ctang-w2c.ch" phase_one P1H(void){ #line 1463 "./cwebdir/ctangle.w" phase= 1; section_count= 0; reset_input(); skip_limbo(); while(!input_has_ended)scan_section(); check_complete(); phase= 2; }
/** * Callback function for data received from the network. Note that * both "available" and "errCode" would be 0 if the read simply timed out. * * @param cls closure * @param buf pointer to received data * @param available number of bytes availabe in "buf", * possibly 0 (on errors) * @param addr address of the sender * @param addrlen size of addr * @param errCode value of errno (on errors receiving) */ static void receive_helper (void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode) { struct GNUNET_CLIENT_Connection *client = cls; struct GNUNET_TIME_Relative remaining; GNUNET_CLIENT_MessageHandler receive_handler; void *receive_handler_cls; GNUNET_assert (GNUNET_NO == client->msg_complete); GNUNET_assert (GNUNET_YES == client->in_receive); client->in_receive = GNUNET_NO; if ((0 == available) || (NULL == client->connection) || (0 != errCode)) { /* signal timeout! */ LOG (GNUNET_ERROR_TYPE_DEBUG, "Timeout in receive_helper, available %u, client->connection %s, errCode `%s'\n", (unsigned int) available, NULL == client->connection ? "NULL" : "non-NULL", STRERROR (errCode)); if (NULL != (receive_handler = client->receiver_handler)) { receive_handler_cls = client->receiver_handler_cls; client->receiver_handler = NULL; receive_handler (receive_handler_cls, NULL); } return; } /* FIXME: optimize for common fast case where buf contains the * entire message and we need no copying... */ /* slow path: append to array */ if (client->received_size < client->received_pos + available) GNUNET_array_grow (client->received_buf, client->received_size, client->received_pos + available); memcpy (&client->received_buf[client->received_pos], buf, available); client->received_pos += available; check_complete (client); /* check for timeout */ remaining = GNUNET_TIME_absolute_get_remaining (client->receive_timeout); if (0 == remaining.rel_value) { /* signal timeout! */ if (NULL != client->receiver_handler) client->receiver_handler (client->receiver_handler_cls, NULL); return; } /* back to receive -- either for more data or to call callback! */ GNUNET_CLIENT_receive (client, client->receiver_handler, client->receiver_handler_cls, remaining); }
void do_task(void *task) { int sock = *(int *)task; free(task); while (1) { int ret = read(sock, recvbuff, 1024); //printf("debug: ret is %d\n", ret); //printf("debug: recv is %s\n", recvbuff); if (ret == -1) { if (errno == EAGAIN) { struct epoll_event event; event.data.fd = sock; event.events = EPOLLIN | EPOLLET; epoll_ctl(epollfd, EPOLL_CTL_DEL, sock, &event); close(sock); } else { perror("server read"); } return; } if (ret == 0) { struct epoll_event event; event.data.fd = sock; event.events = EPOLLIN | EPOLLET; epoll_ctl(epollfd, EPOLL_CTL_DEL, sock, &event); printf("client closed\n"); return; } else { printf("Rcv--------------\n%s\nEnd-------------\n", recvbuff); write_log(recvbuff); } if (check_complete(recvbuff)) { get_path(recvbuff); handle_request(g_path, sock); //printf("debug: handle_request is finished\n"); } else { ret = write(sock, "Invalid request\n", 20); if (ret == -1) { perror("server writes invlid request"); } else if (ret == 0) { printf("client closed\n"); } perror("resource wanted is invaild, ignored"); } } }
/** * Continuation to call the receive callback. * * @param cls our handle to the client connection * @param tc scheduler context */ static void receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CLIENT_Connection *client = cls; GNUNET_CLIENT_MessageHandler handler = client->receiver_handler; const struct GNUNET_MessageHeader *cmsg = (const struct GNUNET_MessageHeader *) client->received_buf; void *handler_cls = client->receiver_handler_cls; uint16_t msize = ntohs (cmsg->size); char mbuf[msize] GNUNET_ALIGN; struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf; client->receive_task = NULL; if ( (GNUNET_SYSERR == client->in_receive) && (GNUNET_YES != client->msg_complete) ) { /* Connection failure, signal to caller! */ client->receiver_handler = NULL; if (NULL != handler) handler (handler_cls, NULL); return; } LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %u and size %u from %s service.\n", ntohs (cmsg->type), msize, client->service_name); GNUNET_assert (GNUNET_YES == client->msg_complete); GNUNET_assert (client->received_pos >= msize); memcpy (msg, cmsg, msize); memmove (client->received_buf, &client->received_buf[msize], client->received_pos - msize); client->received_pos -= msize; client->msg_complete = GNUNET_NO; client->receiver_handler = NULL; check_complete (client); if (NULL != handler) handler (handler_cls, msg); }