TypeData *TypeData::at_force (const Key &key) { dl_assert (structured(), "bug in TypeData"); TypeData *res = at (key); if (res != NULL) { return res; } TypeData *value = get_type (tp_Unknown)->clone(); value->parent_ = this; value->on_changed(); if (key == Key::any_key()) { any_next_ = value; return value; } KeyValue to_add (key, value); NextT::iterator insert_pos = lower_bound (next_.begin(), next_.end(), KeyValue (key, NULL)); next_.insert (insert_pos, to_add); return value; }
void Computer::fold(std::vector<std::vector<double> > *folded, int target_rank) { int my_rank, process_count, point_size=2*integrator->size_real; int max_size = point_size * ceil(end_time / static_interval); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); MPI_Comm_size(MPI_COMM_WORLD, &process_count); MPI_Request send_request; MPI_Status tmp_status; MPI_Barrier(MPI_COMM_WORLD); if (my_rank == target_rank) std::cerr << "About to fold..." << std::flush; // Gather // Prepare send array double *send_array = new double[max_size]; for (int i = 0; (unsigned)i < folded->size(); ++i) { for (int j = 0; j < point_size; ++j) send_array[i * point_size + j] = (*folded)[i][j]; } MPI_Issend(send_array, folded->size() * point_size, MPI_DOUBLE, target_rank, 0, MPI_COMM_WORLD, &send_request); if (my_rank != 0) { MPI_Wait(&send_request, &tmp_status); delete[] send_array; return; } // Receive and align folded->clear(); double *recv_array = new double[max_size]; for (int i = 0; i < process_count; ++i) { int received_count, j = 0; MPI_Status recv_status; MPI_Recv(recv_array, max_size, MPI_DOUBLE, i, 0, MPI_COMM_WORLD, &recv_status); MPI_Get_count(&recv_status, MPI_DOUBLE, &received_count); while (j < received_count) { std::vector<double> to_add(&recv_array[j], &recv_array[j] + point_size); folded->push_back(to_add); j += point_size; } } MPI_Wait(&send_request, &tmp_status); delete[] send_array; delete[] recv_array; if (my_rank == target_rank) std::cerr << " done" << std::endl; }