void handle_work(boost::system::error_code const& ec) { // Get workload from router, until finished if (end_inst == std::to_string(message_[0])) { std::cout << id_ << " Processed: " << total_ << " tasks\n"; } else { ++total_; // Do some random work std::this_thread::sleep_for(std::chrono::milliseconds(std::rand() % 100 + 1)); ping_pong(); } }
int main(int argc, char *argv[]) { char *fname; int fd, num_locks; int c; while ((c = getopt(argc, argv, "rwmc")) != -1) { switch (c){ case 'w': do_writes = 1; break; case 'r': do_reads = 1; break; case 'm': use_mmap = 1; break; case 'c': do_check = 1; break; default: fprintf(stderr, "Unknown option '%c'\n", c); exit(1); } } argv += optind; argc -= optind; if (argc < 2) { printf("ping_pong [options] <file> <num_locks>\n"); printf(" -r do reads\n"); printf(" -w do writes\n"); printf(" -m use mmap\n"); printf(" -c check locks\n"); exit(1); } fname = argv[0]; num_locks = atoi(argv[1]); if (num_locks <= 0) { printf("num_locks should be > 0\n"); exit(1); } fd = open(fname, O_CREAT|O_RDWR, 0600); if (fd == -1) exit(1); ping_pong(fd, num_locks); return 0; }
void determine_time_differences(void) { int i; double *tmp_tds; double start_time, finish_time; if( lrootproc() ) start_time = acc_start_sync(); else start_time = MPI_Wtime(); logging(DBG_SYNC, "determine_time_differences\n"); for( i = 1; i < get_measurement_size(); i++) { MPI_Barrier(get_measurement_comm()); if( get_measurement_rank() == 0 || get_measurement_rank() == i ) ping_pong(0,i); } tmp_tds = skampi_malloc_doubles(get_measurement_size()); if( lrootproc() ) { for( i = 1; i < get_measurement_size(); i++) tmp_tds[i] = tds[get_global_rank(i)]; } assert(get_measurement_size() - 1 >= 0 ); MPI_Bcast(&(tmp_tds[1]), get_measurement_size()-1, MPI_DOUBLE, 0, get_measurement_comm()); if( get_measurement_rank() != 0 ) { logging(DBG_TIMEDIFF, "tds[%d] = %9.1f us\n", get_global_rank(0), tds[get_global_rank(0)]*1.0e6); for( i = 1; i < get_measurement_size(); i++) { tds[get_global_rank(i)] = tmp_tds[i] + tds[get_global_rank(0)]; logging(DBG_TIMEDIFF, "tds[%d] = %9.1f us\n", get_global_rank(i), tds[get_global_rank(i)]*1.0e6); } } free(tmp_tds); MPI_Barrier(get_measurement_comm()); if( lrootproc() ) finish_time = acc_stop_sync(); else finish_time = MPI_Wtime(); rdebug(DBG_TIMEDIFF, "determine_time_differences() on %d processes: %f sec.\n", get_measurement_size(), finish_time - start_time); }
int main(void) { cpu_set_t cpus; pthread_t t; CPU_ZERO(&cpus); CPU_SET(0, &cpus); sched_setaffinity(0, sizeof(cpus), &cpus); pthread_barrier_init(&bar, NULL, 2); test_assert(0 == pthread_create(&t, NULL, pong_thread, NULL)); ping_pong(PING); pthread_join(t, NULL); atomic_puts("EXIT-SUCCESS"); return 0; }
int main(int argc, char *argv[]) { int fd = -1; int result = 0; if (argc < 4) { usage(argv[0]); } else { fd = open_port(argv[1]); if (fd == -1) { printf("Could not open device: %s\n", argv[1]); return 1; } if (ping_pong(fd) != 0) { printf("Could not communicate with device: %s\n", argv[1]); close(fd); return 1; } if (strcmp(argv[2], "light") == 0 && argc >= 5) { if (strcmp(argv[4], "pwm") == 0 && argc < 6) { printf("Invalid number of parameters for light pwm\n"); usage(argv[0]); close(fd); return 1; } result = light_command(fd, &argv[3]); } else if (strcmp(argv[2], "all") == 0) { if (strcmp(argv[3], "pwm") == 0 && argc < 5) { printf("Invalid number of parameters for all pwm\n"); usage(argv[0]); close(fd); return 1; } result = all_command(fd, &argv[3]); } else if (strcmp(argv[2], "settings") == 0 && strcmp(argv[3], "read") == 0) { struct Settings settings; int n = read_settings(fd, &settings); if (n != 0) { close(fd); return 1; } if (argc >= 5 && strcmp(argv[4], "hex") == 0) { print_settings_hex(&settings); } else { print_settings(&settings); } } else if (strcmp(argv[2], "settings") == 0 && strcmp(argv[3], "write") == 0 && argc > 4) { result = write_settings(fd, argv[4]); } else { printf("Invalid command\n\n"); usage(argv[0]); } } if (fd != -1) { close(fd); } return result; }
int dc_close(int fd) { int res = 0; int tmp; int32_t size; int32_t closemsg[6]; int msglen; struct vsp_node *node; #ifdef DC_CALL_TRACE showTraceBack(); #endif /* nothing wrong ... yet */ dc_errno = DEOK; node = delete_vsp_node(fd); if (node == NULL) { /* we have not such file descriptor, so lets give a try to system */ dc_debug(DC_INFO, "Using system native close for [%d].", fd); return system_close(fd); } if ( node->lcb != NULL ) { dc_lcb_clean( node ); } dc_real_fsync( node ); if(node->unsafeWrite > 1) { size = htonl(-1); /* send end of data */ writen(node->dataFd, (char *) &size, sizeof(size), NULL); /* FIXME: error detection missing */ if (get_fin(node) < 0) { dc_debug(DC_ERROR, "dc_close: mover did not FIN the data blocks."); res = -1; } } if(node->reference == 0 ) { if( (node->sum != NULL) && ( node->sum->isOk == 1 ) ) { closemsg[0] = htonl(20); closemsg[2] = htonl(12); closemsg[3] = htonl(DCAP_DATA_SUM); closemsg[4] = htonl(node->sum->type); closemsg[5] = htonl(node->sum->sum); msglen = 6; dc_debug(DC_INFO, "File checksum is: %u", node->sum->sum); }else{ closemsg[0] = htonl(4); msglen = 2; } closemsg[1] = htonl(IOCMD_CLOSE); /* actual command */ dc_debug(DC_IO, "Sending CLOSE for fd:%d ID:%d.", node->dataFd, node->queueID); check_timeout_envar(); dcap_set_alarm(closeTimeOut > 0 ? closeTimeOut : DCAP_IO_TIMEOUT/4); tmp = sendDataMessage(node, (char *) closemsg, msglen*sizeof(int32_t), ASCII_OK, NULL); /* FIXME: error detection missing */ if( tmp < 0 ) { dc_debug(DC_ERROR, "sendDataMessage failed."); /* ignore close errors if file was open for read */ if(node->flags & O_WRONLY) { res = -1; } if(isIOFailed) { isIOFailed = 0; /* command line dwon */ if(!ping_pong(node)) { /* remove file descriptor from the list of control lines in use */ lockMember(); deleteMemberByValue(node->fd); unlockMember(); pollDelete(node->fd); close_control_socket(node->fd, node->tunnel); } } } dcap_set_alarm(0); deleteQueue(node->queueID); } /* * Even if there is still a reference to the dcap session, * we have to close local socket descriptor. */ close_data_socket(node->dataFd); node_destroy(node); return res; }
void start() { ping_pong(); }
static void* pong_thread(void* unused) { ping_pong(PONG); return NULL; }
int main(int argc, char *argv[]) { char *fname; int fd, num_locks; int c; while ((c = getopt(argc, argv, "rwmcl")) != -1) { switch (c){ case 'w': do_writes = 1; break; case 'r': do_reads = 1; break; case 'm': use_mmap = 1; break; case 'c': do_check = 1; break; case 'l': do_brl_test = 1; break; default: fprintf(stderr, "Unknown option '%c'\n", c); exit(1); } } argv += optind; argc -= optind; if (argc < 1) { usage(); exit(1); } fname = argv[0]; fd = open(fname, O_CREAT|O_RDWR, 0600); if (fd == -1) { exit(1); } if (do_brl_test) { if (lock_range(fd, 0, 0, false) != 0) { printf("file already locked, calling check_lock to tell us who has it locked:\n"); (void)check_lock(fd, 0, 0); printf("Working POSIX byte range locks\n"); exit(0); } printf("Holding lock, press any key to continue...\n"); printf("You should run the same command on another node now.\n"); (void)getchar(); printf("Good bye.\n"); exit(0); } if (argc < 2) { usage(); exit(1); } num_locks = atoi(argv[1]); if (num_locks <= 0) { printf("num_locks should be > 0\n"); exit(1); } ping_pong(fd, num_locks); return 0; }