int network_manager_unregister_peer_for_polling(struct network_manager* nm, struct network_peer* peer) { uintptr_t p = (uintptr_t)peer; int* psock = NULL; int sock; JLG(psock, nm->poll_socket_by_peer, p); if(psock == NULL) return -1; // doesn't exist sock = *psock; int rc; JLD(rc, nm->poll_socket_by_peer, p); FD_CLR(sock, &nm->poll_read_fds); FD_CLR(sock, &nm->poll_write_fds); FD_CLR(sock, &nm->poll_exception_fds); if(sock == nm->poll_max_fd) { size_t num_fds = vector_count(&nm->poll_fds); // Need to figure out what the previous max fd was, which means.. qsort(vector_data(&nm->poll_fds), (size_t)num_fds, sizeof(uintptr_t), compint); int old_fd = (int)vector_pop(&nm->poll_fds); assert(old_fd == sock); nm->poll_max_fd = 0; if(num_fds > 1) { nm->poll_max_fd = vector_get(&nm->poll_fds, num_fds - 2); } } return 0; }
void dylan_format (STREAM stream, D dylan_string, D dylan_arguments) { BOOL percent_p = FALSE; char* string = string_data(dylan_string); D* arguments = vector_data(dylan_arguments); int argument_count = vector_size(dylan_arguments), argument_index = 0, size = (int)strlen(string), i; for (i = 0; i < size; i++) { char c = string[i]; if (percent_p) { char cc = (char)toupper(c); switch (cc) { case 'S': case 'C': if (argument_index < argument_count) print_object(stream, arguments[argument_index++], FALSE, 0); else put_string("**MISSING**", stream); break; case '=': if (argument_index < argument_count) print_object(stream, arguments[argument_index++], TRUE, 0); else put_string("**MISSING**", stream); break; case 'D': case 'X': case 'O': case 'B': if (argument_index < argument_count) print_object(stream, arguments[argument_index++], (BOOL)cc, 0); else put_string("**MISSING**", stream); break; case '%': put_char('%', stream); break; default: ; } percent_p = FALSE; } else if (c == '%') percent_p = TRUE; else put_char(c, stream); } }
D c_primitive_stop_timer() { getrusage(RUSAGE_SELF, &stop); stop.ru_utime.tv_usec -= start.ru_utime.tv_usec; stop.ru_utime.tv_sec -= start.ru_utime.tv_sec; if (stop.ru_utime.tv_usec < 0) { stop.ru_utime.tv_usec += 1000000; stop.ru_utime.tv_sec -= 1; } { SOV* value = make_dylan_vector(2); D* data = (D*)vector_data(value); data[0] = I(stop.ru_utime.tv_sec); data[1] = I(stop.ru_utime.tv_usec); return((D)value); } }
void RBEvaluation::read_in_vectors(System& sys, std::vector<NumericVector<Number>*>& vectors, const std::string& directory_name, const std::string& data_name, const bool read_binary_vectors) { START_LOG("read_in_vectors()", "RBEvaluation"); //libMesh::out << "Reading in the basis functions..." << std::endl; // Make sure processors are synced up before we begin this->comm().barrier(); std::ostringstream file_name; const std::string basis_function_suffix = (read_binary_vectors ? ".xdr" : ".dat"); struct stat stat_info; file_name << directory_name << "/" << data_name << "_header" << basis_function_suffix; Xdr header_data(file_name.str(), read_binary_vectors ? DECODE : READ); // set the version number in header_data from io_version_string // (same code as in EquationSystemsIO::_read_impl) std::string io_version_string = get_io_version_string(); std::string::size_type lm_pos = io_version_string.find("libMesh"); std::istringstream iss(io_version_string.substr(lm_pos + 8)); int ver_major = 0, ver_minor = 0, ver_patch = 0; char dot; iss >> ver_major >> dot >> ver_minor >> dot >> ver_patch; header_data.set_version(LIBMESH_VERSION_ID(ver_major, ver_minor, ver_patch)); // We need to call sys.read_header (e.g. to set _written_var_indices properly), // but by setting the read_header argument to false, it doesn't reinitialize the system sys.read_header(header_data, io_version_string, /*read_header=*/false, /*read_additional_data=*/false); // Following EquationSystemsIO::read, we use a temporary numbering (node major) // before writing out the data MeshTools::Private::globally_renumber_nodes_and_elements(sys.get_mesh()); const bool read_legacy_format = false; if (read_legacy_format) { // Use System::read_serialized_data to read in the basis functions // into this->solution and then swap with the appropriate // of basis function. for(unsigned int i=0; i<vectors.size(); i++) { file_name.str(""); // reset the string file_name << directory_name << "/" << data_name << i << basis_function_suffix; // On processor zero check to be sure the file exists if (this->processor_id() == 0) { int stat_result = stat(file_name.str().c_str(), &stat_info); if (stat_result != 0) libmesh_error_msg("File does not exist: " << file_name.str()); } Xdr vector_data(file_name.str(), read_binary_vectors ? DECODE : READ); // The bf_data needs to know which version to read. vector_data.set_version(LIBMESH_VERSION_ID(ver_major, ver_minor, ver_patch)); sys.read_serialized_data(vector_data, false); vectors[i] = NumericVector<Number>::build(sys.comm()).release(); vectors[i]->init (sys.n_dofs(), sys.n_local_dofs(), false, PARALLEL); // No need to copy, just swap // *vectors[i] = *solution; vectors[i]->swap(*sys.solution); } } //------------------------------------------------------ // new implementation else { // Allocate storage for each vector for(unsigned int i=0; i<vectors.size(); i++) { vectors[i] = NumericVector<Number>::build(sys.comm()).release(); vectors[i]->init (sys.n_dofs(), sys.n_local_dofs(), false, PARALLEL); } file_name.str(""); file_name << directory_name << "/" << data_name << "_data" << basis_function_suffix; // On processor zero check to be sure the file exists if (this->processor_id() == 0) { int stat_result = stat(file_name.str().c_str(), &stat_info); if (stat_result != 0) libmesh_error_msg("File does not exist: " << file_name.str()); } Xdr vector_data(file_name.str(), read_binary_vectors ? DECODE : READ); // The vector_data needs to know which version to read. vector_data.set_version(LIBMESH_VERSION_ID(ver_major, ver_minor, ver_patch)); sys.read_serialized_vectors (vector_data, vectors); } //------------------------------------------------------ // Undo the temporary renumbering sys.get_mesh().fix_broken_node_and_element_numbering(); //libMesh::out << "Finished reading in the basis functions..." << std::endl; STOP_LOG("read_in_vectors()", "RBEvaluation"); }
void RBEvaluation::read_in_vectors_from_multiple_files( System& sys, std::vector< std::vector<NumericVector<Number>*>* > multiple_vectors, const std::vector<std::string>& multiple_directory_names, const std::vector<std::string>& multiple_data_names, const bool read_binary_vectors) { START_LOG("read_in_vectors_from_multiple_files()", "RBEvaluation"); unsigned int n_files = multiple_vectors.size(); unsigned int n_directories = multiple_directory_names.size(); unsigned int n_data_names = multiple_data_names.size(); libmesh_assert( (n_files == n_directories) && (n_files == n_data_names) ); if(n_files == 0) { return; } // Make sure processors are synced up before we begin this->comm().barrier(); std::ostringstream file_name; const std::string basis_function_suffix = (read_binary_vectors ? ".xdr" : ".dat"); struct stat stat_info; // Assume that all the headers are the same, hence we can just use the first one. file_name << multiple_directory_names[0] << "/" << multiple_data_names[0] << "_header" << basis_function_suffix; Xdr header_data(file_name.str(), read_binary_vectors ? DECODE : READ); // set the version number in header_data from io_version_string // (same code as in EquationSystemsIO::_read_impl) std::string io_version_string = get_io_version_string(); std::string::size_type lm_pos = io_version_string.find("libMesh"); std::istringstream iss(io_version_string.substr(lm_pos + 8)); int ver_major = 0, ver_minor = 0, ver_patch = 0; char dot; iss >> ver_major >> dot >> ver_minor >> dot >> ver_patch; header_data.set_version(LIBMESH_VERSION_ID(ver_major, ver_minor, ver_patch)); // We need to call sys.read_header (e.g. to set _written_var_indices properly), // but by setting the read_header argument to false, it doesn't reinitialize the system sys.read_header( header_data, io_version_string, /*read_header=*/false, /*read_additional_data=*/false); // Following EquationSystemsIO::read, we use a temporary numbering (node major) // before writing out the data MeshTools::Private::globally_renumber_nodes_and_elements( sys.get_mesh()); for(unsigned int data_index=0; data_index<n_directories; data_index++) { std::vector<NumericVector<Number>*>& vectors = *multiple_vectors[data_index]; // Allocate storage for each vector for(unsigned int i=0; i<vectors.size(); i++) { vectors[i] = NumericVector<Number>::build( sys.comm()).release(); vectors[i]->init ( sys.n_dofs(), sys.n_local_dofs(), false, PARALLEL); } file_name.str(""); file_name << multiple_directory_names[data_index] << "/" << multiple_data_names[data_index] << "_data" << basis_function_suffix; // On processor zero check to be sure the file exists if (this->processor_id() == 0) { int stat_result = stat(file_name.str().c_str(), &stat_info); if (stat_result != 0) { libmesh_error_msg("File does not exist: " << file_name.str()); } } Xdr vector_data(file_name.str(), read_binary_vectors ? DECODE : READ); // The vector_data needs to know which version to read. vector_data.set_version(LIBMESH_VERSION_ID(ver_major, ver_minor, ver_patch)); sys.read_serialized_vectors (vector_data, vectors); } // Undo the temporary renumbering sys.get_mesh().fix_broken_node_and_element_numbering(); STOP_LOG("read_in_vectors_from_multiple_files()", "RBEvaluation"); }