void Device_states_remove_state(Device_states* states, uint32_t id) { rassert(states != NULL); rassert(id > 0); const uint32_t h = id_hash(id); Entry** ref = &states->entries[h]; Entry* cur = states->entries[h]; while (cur != NULL) { rassert(cur->state != NULL); if (cur->state->device_id == id) { *ref = cur->next; del_Entry(cur); break; } ref = &cur->next; cur = cur->next; } return; }
bool Device_states_add_state(Device_states* states, Device_state* state) { rassert(states != NULL); rassert(state != NULL); const uint32_t h = id_hash(state->device_id); Entry* entry = new_Entry(state, states->thread_count); if (entry == NULL) return false; Entry* tail = states->entries[h]; entry->next = tail; states->entries[h] = entry; Device_state_reset(state); return true; }
static Entry* get_entry(const Device_states* states, uint32_t id) { rassert(states != NULL); rassert(id > 0); const uint32_t h = id_hash(id); Entry* target = states->entries[h]; while (target != NULL) { rassert(target->state != NULL); if (target->state->device_id == id) return target; target = target->next; } rassert(false); return NULL; }
int store_request(jsonrpc_request_t* req) { int key = id_hash(req->id); jsonrpc_request_t* existing; if ((existing = request_table[key])) { /* collision */ jsonrpc_request_t* i; for(i=existing; i; i=i->next) { if (i == NULL) { i = req; LM_ERR("!!!!!!!"); return 1; } if (i->next == NULL) { i->next = req; return 1; } } } else { request_table[key] = req; } return 1; }
jsonrpc_request_t* pop_request(int id) { int key = id_hash(id); jsonrpc_request_t* req = request_table[key]; jsonrpc_request_t* prev_req = NULL; while (req && req->id != id) { prev_req = req; if (!(req = req->next)) { break; }; } if (req && req->id == id) { if (prev_req != NULL) { prev_req->next = req->next; } else { request_table[key] = NULL; } return req; } return 0; }
template <typename INT> void FaceGenerator::generate_faces(INT /*dummy*/) { Ioss::NodeBlock *nb = region_.get_node_blocks()[0]; std::vector<INT> ids; nb->get_field_data("ids", ids); // Convert ids into hashed-ids auto starth = std::chrono::high_resolution_clock::now(); std::vector<size_t> hash_ids; hash_ids.reserve(ids.size()); for (auto id : ids) { hash_ids.push_back(id_hash(id)); } auto endh = std::chrono::high_resolution_clock::now(); size_t numel = region_.get_property("element_count").get_int(); faces_.reserve(3.3 * numel); Ioss::ElementBlockContainer ebs = region_.get_element_blocks(); for (auto eb : ebs) { const Ioss::ElementTopology *topo = eb->topology(); // Only handle continuum elements at this time... if (topo->parametric_dimension() != 3) { continue; } std::vector<INT> connectivity; eb->get_field_data("connectivity_raw", connectivity); std::vector<INT> elem_ids; eb->get_field_data("ids", elem_ids); int num_face_per_elem = topo->number_faces(); assert(num_face_per_elem <= 6); std::array<Ioss::IntVector, 6> face_conn; std::array<int, 6> face_count; for (int face = 0; face < num_face_per_elem; face++) { face_conn[face] = topo->face_connectivity(face + 1); face_count[face] = topo->face_type(face + 1)->number_corner_nodes(); } int num_node_per_elem = topo->number_nodes(); size_t num_elem = eb->get_property("entity_count").get_int(); for (size_t elem = 0, offset = 0; elem < num_elem; elem++, offset += num_node_per_elem) { for (int face = 0; face < num_face_per_elem; face++) { size_t id = 0; assert(face_count[face] <= 4); std::array<size_t, 4> conn = {{0, 0, 0, 0}}; for (int j = 0; j < face_count[face]; j++) { size_t fnode = offset + face_conn[face][j]; size_t gnode = connectivity[fnode]; conn[j] = ids[gnode - 1]; id += hash_ids[gnode - 1]; } create_face(faces_, id, conn, elem_ids[elem]); } } } auto endf = std::chrono::high_resolution_clock::now(); resolve_parallel_faces(region_, faces_, hash_ids, (INT)0); auto endp = std::chrono::high_resolution_clock::now(); auto diffh = endh - starth; auto difff = endf - endh; auto diffp = endp - endf; std::cout << "Node ID hash time: \t" << std::chrono::duration<double, std::milli>(diffh).count() << " ms\t" << hash_ids.size() / std::chrono::duration<double>(diffh).count() << " nodes/second\n"; std::cout << "Face generation time:\t" << std::chrono::duration<double, std::milli>(difff).count() << " ms\t" << faces_.size() / std::chrono::duration<double>(difff).count() << " faces/second.\n"; #ifdef HAVE_MPI size_t proc_count = region_.get_database()->util().parallel_size(); if (proc_count > 1) { std::cout << "Parallel time: \t" << std::chrono::duration<double, std::milli>(diffp).count() << " ms\t" << faces_.size() / std::chrono::duration<double>(diffp).count() << " faces/second.\n"; } #endif std::cout << "Total time: \t" << std::chrono::duration<double, std::milli>(endp - starth).count() << " ms\n\n"; }