void publish( rclcpp::Node::SharedPtr node, const std::string & message_type, std::vector<typename T::SharedPtr> messages, size_t number_of_cycles = 100) { auto start = std::chrono::steady_clock::now(); rmw_qos_profile_t custom_qos_profile = rmw_qos_profile_default; custom_qos_profile.depth = messages.size(); auto publisher = node->create_publisher<T>( std::string("test/message/") + message_type, custom_qos_profile); rclcpp::WallRate cycle_rate(10); rclcpp::WallRate message_rate(100); size_t cycle_index = 0; // publish all messages up to number_of_cycles times, longer sleep between each cycle while (rclcpp::ok() && cycle_index < number_of_cycles) { size_t message_index = 0; // publish all messages one by one, shorter sleep between each message while (rclcpp::ok() && message_index < messages.size()) { printf("publishing message #%zu\n", message_index + 1); publisher->publish(messages[message_index]); ++message_index; message_rate.sleep(); } ++cycle_index; cycle_rate.sleep(); } auto end = std::chrono::steady_clock::now(); std::chrono::duration<float> diff = (end - start); printf("published for %f seconds\n", diff.count()); }
void benchmark (struct pe_vars v, long * msg_buffer) { static double pwrk[_SHMEM_REDUCE_SYNC_SIZE]; static long psync[_SHMEM_BCAST_SYNC_SIZE]; static double mr, mr_sum; unsigned long size, i; memset(psync, _SHMEM_SYNC_VALUE, sizeof(long[_SHMEM_BCAST_SYNC_SIZE])); /* * Warmup */ if (v.me < v.pairs) { //for (i = 0; i < (ITERS_LARGE * MAX_MSG_SZ); i += MAX_MSG_SZ) { for (i = 0; i < ITERS_LARGE; i += 1) { //shmem_putmem(&msg_buffer[i], &msg_buffer[i], MAX_MSG_SZ, v.nxtpe); shmem_long_put(&msg_buffer[i], &msg_buffer[i], MAX_MSG_SZ, v.nxtpe); } } shmem_barrier_all(); /* * Benchmark */ for (size = 1; size <= MAX_MSG_SZ; size <<= 1) { i = size < LARGE_THRESHOLD ? ITERS_SMALL : ITERS_LARGE; mr = message_rate(v, msg_buffer, size, i); shmem_double_sum_to_all(&mr_sum, &mr, 1, 0, 0, v.npes, pwrk, psync); print_message_rate(v.me, size, mr_sum); } }
void benchmark (long * msg_buffer, int me, int pairs, int nxtpe, MPI_Win win) { static double mr, mr_sum; int iters; if (msg_buffer == NULL) { printf("Input buffer is NULL, no reason to proceed\n"); exit(-1); } /* * Warmup */ if (me < pairs) { for (int i = 0; i < ITERS_LARGE; i += 1) { MPI_Put ((msg_buffer + i*MAX_MSG_SZ), MAX_MSG_SZ, MPI_LONG, nxtpe, i*MAX_MSG_SZ, MAX_MSG_SZ, MPI_LONG, win); MPI_Win_flush_local (nxtpe, win); } } MPI_Win_flush_all(win); MPI_Barrier(MPI_COMM_WORLD); /* * Benchmark */ for (long size = 1; size <= MAX_MSG_SZ; size <<= 1) { iters = size < LARGE_THRESHOLD ? ITERS_SMALL : ITERS_LARGE; mr = message_rate(msg_buffer, size, iters, me, pairs, nxtpe, win); MPI_Reduce(&mr, &mr_sum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); print_message_rate(size, mr_sum, me); } }