OSystem::OSystem() : m_layer(), m_lib_loader() { m_layer.reset(); m_lib_loader.reset(); #ifdef CF_HAVE_DLOPEN if ( is_null( m_lib_loader ) ) m_lib_loader.reset( new PosixDlopenLibLoader() ); #endif #ifdef CF_OS_LINUX if ( is_null( m_layer ) ) m_layer.reset( new Linux::OSystemLayer() ); #else #ifdef CF_OS_MACOSX if ( is_null( m_layer ) ) m_layer.reset( new MacOSX::OSystemLayer() ); #else #ifdef CF_OS_WINDOWS if ( is_null( m_layer ) ) m_layer.reset( new Win32::OSystemLayer() ); if ( is_null( m_lib_loader ) ) m_lib_loader.reset( new Win32::LibLoader() ); #else #error "Unkown operating system: not Windows, MacOSX or Linux" #endif #endif #endif cf_assert ( is_not_null( m_layer ) ); cf_assert ( is_not_null( m_lib_loader ) ); std::vector< boost::filesystem::path > default_paths(1, boost::filesystem::path(CF_BUILD_DIR) / boost::filesystem::path("dso")); m_lib_loader->set_search_paths(default_paths); }
boost::tuple<Common::Component&,Uint> CUnifiedData::location_v2(const Uint data_glb_idx) { cf_assert(data_glb_idx<m_size); const Uint data_vector_idx = std::upper_bound(m_data_indices->array().begin(), m_data_indices->array().end(), data_glb_idx) - 1 - m_data_indices->array().begin(); cf_assert(m_data_indices->array()[data_vector_idx] <= data_glb_idx ); return boost::tuple<Common::Component&,Uint>(*m_data_vector[data_vector_idx], data_glb_idx - m_data_indices->array()[data_vector_idx]); }
/// Get the const component and local index in the component /// given a continuous index spanning multiple components /// @param [in] data_glb_idx continuous index covering multiple components /// @return boost::tuple<Uint component_idx, Uint idx_in_component> boost::tuple<Uint,Uint> CUnifiedData::location_idx(const Uint data_glb_idx) const { cf_assert(data_glb_idx<m_size); const Uint data_vector_idx = std::upper_bound(m_data_indices->array().begin(), m_data_indices->array().end(), data_glb_idx) - 1 - m_data_indices->array().begin(); cf_assert(data_vector_idx<m_data_vector.size()); return boost::make_tuple(data_vector_idx, data_glb_idx - m_data_indices->array()[data_vector_idx]); }
void ListeningThread::add_communicator( Communicator comm ) { m_mutex.lock(); cf_assert( comm != MPI_COMM_NULL ); cf_assert( m_comms.find(comm) == m_comms.end() ); m_comms[comm] = new ListeningInfo(); m_mutex.unlock(); }
void VectorialFunction::evaluate( const RealVector& var_values, RealVector& ret_value) const { cf_assert(m_is_parsed); cf_assert(var_values.size() == m_nbvars); // evaluate and store the functions line by line in the vector std::vector<FunctionParser*>::const_iterator parser = m_parsers.begin(); std::vector<FunctionParser*>::const_iterator end = m_parsers.end(); Uint i = 0; for( ; parser != end ; ++parser, ++i ) ret_value[i] = (*parser)->Eval(&var_values[0]); }
void Triag2DLagrangeP2::mapped_coordinates(const CoordsT& coord, const NodeMatrixT& nodes, MappedCoordsT& map_coord) { throw Common::NotImplemented( FromHere(), "" ); cf_assert(coord.size() == 2); cf_assert(map_coord.size() == 2); cf_assert(nodes.size() == 6); const Real invDet = 1. / jacobian_determinant(nodes); map_coord[KSI] = invDet * ((nodes(2, YY) - nodes(0, YY))*coord[XX] + (nodes(0, XX) - nodes(2, XX))*coord[YY] - nodes(0, XX)*nodes(2, YY) + nodes(2, XX)*nodes(0, YY)); map_coord[ETA] = invDet * ((nodes(0, YY) - nodes(1, YY))*coord[XX] + (nodes(1, XX) - nodes(0, XX))*coord[YY] + nodes(0, XX)*nodes(1, YY) - nodes(1, XX)*nodes(0, YY)); }
void ListeningThread::remove_comunicator( Communicator comm ) { m_mutex.lock(); cf_assert( comm!= MPI_COMM_NULL ); std::map<Communicator, ListeningInfo*>::iterator it = m_comms.find(comm); cf_assert( it != m_comms.end() ); m_comms.erase(it); m_mutex.unlock(); }
RealVector& VectorialFunction::operator()( const RealVector& var_values) { cf_assert(m_is_parsed); cf_assert(var_values.size() == m_nbvars); // evaluate and store the functions line by line in the result vector std::vector<FunctionParser*>::const_iterator parser = m_parsers.begin(); std::vector<FunctionParser*>::const_iterator end = m_parsers.end(); Uint i = 0; for( ; parser != end ; ++parser, ++i ) m_result[i] = (*parser)->Eval(&var_values[0]); return m_result; }
int as_record_write_from_pickle(as_storage_rd* rd) { cf_assert(as_bin_inuse_has(rd), AS_RECORD, "unexpected binless pickle"); return as_storage_record_write(rd); }
void demarshal_file_handle_init() { struct rlimit rl; pthread_mutex_lock(&g_file_handle_a_LOCK); if (g_file_handle_a == 0) { if (-1 == getrlimit(RLIMIT_NOFILE, &rl)) { cf_crash(AS_DEMARSHAL, "getrlimit: %s", cf_strerror(errno)); } // Initialize the message pointer array and the unread byte counters. g_file_handle_a = cf_calloc(rl.rlim_cur, sizeof(as_proto *)); cf_assert(g_file_handle_a, AS_DEMARSHAL, CF_CRITICAL, "allocation: %s", cf_strerror(errno)); g_file_handle_a_sz = rl.rlim_cur; for (int i = 0; i < g_file_handle_a_sz; i++) { cf_queue_push(g_freeslot, &i); } pthread_create(&g_demarshal_reaper_th, 0, thr_demarshal_reaper_fn, 0); // If config value is 0, set a maximum proto size based on the RLIMIT. if (g_config.n_proto_fd_max == 0) { g_config.n_proto_fd_max = rl.rlim_cur / 2; cf_info(AS_DEMARSHAL, "setting default client file descriptors to %d", g_config.n_proto_fd_max); } } pthread_mutex_unlock(&g_file_handle_a_LOCK); }
typename LIB::Ptr library () { const std::string lname = LIB::library_namespace(); //instead of LIB::type_name(); Component::Ptr clib = get_child_ptr(lname); typename LIB::Ptr lib; if ( is_null(clib) ) // doesnt exist so build it { CF::Common::TypeInfo::instance().regist< LIB >( lname ); lib = create_component_ptr< LIB >(lname); cf_assert( is_not_null(lib) ); return lib; } // try to convert existing ptr to LIB::Ptr and return it lib = clib->as_ptr<LIB>(); if( is_null(lib) ) // conversion failed throw CastingFailed( FromHere(), "Found component in CLibraries with name " + lname + " but is not the actual library " + LIB::type_name() ); return lib; }
void GrowOverlap::execute() { CMesh& mesh = *m_mesh.lock(); Geometry& nodes = mesh.geometry(); const std::vector<Component::Ptr>& mesh_elements = mesh.elements().components(); CFaceCellConnectivity& face2cell = mesh.create_component<CFaceCellConnectivity>("face2cell"); face2cell.setup(mesh.topology()); std::map<Uint,Uint> glb_node_2_loc_node; std::map<Uint,Uint>::iterator glb_node_not_found = glb_node_2_loc_node.end(); for (Uint n=0; n<nodes.size(); ++n) { if ( glb_node_2_loc_node.find(nodes.glb_idx()[n]) == glb_node_not_found ) { glb_node_2_loc_node[nodes.glb_idx()[n]] = n; } else { std::cout << PERank << "node glb idx " << nodes.glb_idx()[n] << " already exists..." << std::endl; } } std::map<Uint,Uint> glb_elem_2_loc_elem; std::map<Uint,Uint>::iterator glb_elem_not_found = glb_elem_2_loc_elem.end(); for (Uint e=0; e<mesh.elements().size(); ++e) { Component::Ptr comp; Uint idx; boost::tie(comp,idx) = mesh.elements().location(e); if ( CElements::Ptr elements = comp->as_ptr<CElements>() ) { if ( glb_elem_2_loc_elem.find(elements->glb_idx()[idx]) == glb_elem_not_found ) { glb_elem_2_loc_elem[elements->glb_idx()[idx]] = e; } else { std::cout << PERank << "elem glb idx " << elements->glb_idx()[idx] << " already exists..." << std::endl; } } } std::set<Uint> bdry_nodes; for (Uint f=0; f<face2cell.size(); ++f) { cf_assert(f < face2cell.is_bdry_face().size()); if (face2cell.is_bdry_face()[f]) { boost_foreach(const Uint node, face2cell.face_nodes(f)) bdry_nodes.insert(nodes.glb_idx()[node]); } }
inline void all_gathervm_impl(const Communicator& comm, const T* in_values, const int in_n, const int *in_map, T* out_values, const int *out_n, const int *out_map, const int stride ) { // get data type and number of processors Datatype type = PE::get_mpi_datatype(*in_values); int nproc; MPI_CHECK_RESULT(MPI_Comm_size,(comm,&nproc)); // if stride is smaller than one and unsupported functionality cf_assert( stride>0 ); // compute displacements both on send an receive side // also compute stride-multiplied send and receive counts int *out_nstride=new int[nproc]; int *out_disp=new int[nproc]; out_disp[0]=0; for(int i=0; i<nproc-1; i++) { out_nstride[i]=stride*out_n[i]; out_disp[i+1]=out_disp[i]+out_nstride[i]; } out_nstride[nproc-1]=out_n[nproc-1]*stride; // compute total number of send and receive items const int in_sum=stride*in_n; const int out_sum=out_disp[nproc-1]+stride*out_n[nproc-1]; // set up in_buf T *in_buf=(T*)in_values; if (in_map!=0) { if ( (in_buf=new T[in_sum+1]) == (T*)0 ) throw CF::Common::NotEnoughMemory(FromHere(),"Could not allocate temporary buffer."); // +1 for avoiding possible zero allocation if (stride==1) { for(int i=0; i<in_sum; i++) in_buf[i]=in_values[in_map[i]]; } else { for(int i=0; i<in_sum/stride; i++) memcpy(&in_buf[stride*i],&in_values[stride*in_map[i]],stride*sizeof(T)); } } // set up out_buf T *out_buf=out_values; if ((out_map!=0)||(in_values==out_values)) { if ( (out_buf=new T[out_sum+1]) == (T*)0 ) throw CF::Common::NotEnoughMemory(FromHere(),"Could not allocate temporary buffer."); // +1 for avoiding possible zero allocation } // do the communication MPI_CHECK_RESULT(MPI_Allgatherv, (in_buf, in_sum, type, out_buf, out_nstride, out_disp, type, comm)); // re-populate out_values if (out_map!=0) { if (stride==1) { for(int i=0; i<out_sum; i++) out_values[out_map[i]]=out_buf[i]; } else { for(int i=0; i<out_sum/stride; i++) memcpy(&out_values[stride*out_map[i]],&out_buf[stride*i],stride*sizeof(T)); } delete[] out_buf; } else if (in_values==out_values) { memcpy(out_values,out_buf,out_sum*sizeof(T)); delete[] out_buf; } // free internal memory if (in_map!=0) delete[] in_buf; delete[] out_disp; delete[] out_nstride; }
CNode::Ptr CNodeBuilders::buildCNode( const QString & componentType, const std::string & name ) const { cf_assert( m_builders.contains( componentType ) ); CBuilder & builder = m_builders[componentType]->as_type<CBuilder>(); return builder.build( name )->as_ptr_checked<CNode>(); }
XmlNode Protocol::add_signal_frame ( XmlNode& node, const std::string & target, const URI & sender, const URI & receiver, bool user_trans ) { cf_assert(sender.scheme() == URI::Scheme::CPATH); cf_assert(receiver.scheme() == URI::Scheme::CPATH); std::string uuid = boost::lexical_cast<std::string>(boost::uuids::random_generator()()); XmlNode signalnode = node.add_node( Tags::node_frame() ); signalnode.set_attribute( "type", Tags::node_type_signal() ); signalnode.set_attribute( "target", target ); signalnode.set_attribute( "sender", sender.string() ); signalnode.set_attribute( "receiver", receiver.string() ); signalnode.set_attribute( "transaction", user_trans ? "user" : "auto" ); signalnode.set_attribute( "frameid", uuid ); return signalnode; }
void NLog::signal_message(SignalArgs & node) { SignalOptions options( node ); std::string typeStr = options.value<std::string>("type"); std::string message = options.value<std::string>("text"); LogMessage::Type type = LogMessage::Convert::instance().to_enum(typeStr); cf_assert(type != LogMessage::INVALID); this->appendToLog(type, true, message.c_str()); }
void CPartitioner::query_list_of_connected_objects(void *data, int sizeGID, int sizeLID, int num_obj, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, int *num_edges, ZOLTAN_ID_PTR nborGID, int *nborProc, int wgt_dim, float *ewgts, int *ierr) { CMeshPartitioner& p = *(CMeshPartitioner *)data; *ierr = ZOLTAN_OK; p.list_of_connected_objects_in_part(PE::Comm::instance().rank(),nborGID); p.list_of_connected_procs_in_part(PE::Comm::instance().rank(),nborProc); // for debugging #if 0 const Uint nb_obj = p.nb_owned_objects(); std::vector<Uint> numEdges(nb_obj); Uint tot_nb_edges = p.nb_connected_objects(numEdges); std::vector<Uint> conn_glbID(tot_nb_edges); p.list_of_connected_objects(conn_glbID); std::vector<Uint> glbID(nb_obj); p.list_of_owned_objects(glbID); PEProcessSortedExecute(-1, CFdebug << RANK << "conn_glbID =\n"; Uint cnt = 0; index_foreach( e, const Uint nbEdge, numEdges) { if (p.is_node(glbID[e])) CFdebug << " N" << p.to_node_glb(glbID[e]) << ": "; else CFdebug << " E" << p.to_elem_glb(glbID[e]) << ": "; for (Uint c=cnt; c<cnt+nbEdge; ++c) { if (p.is_node(conn_glbID[c])) CFdebug << " N" << p.to_node_glb(conn_glbID[c]); else CFdebug << " E" << p.to_elem_glb(conn_glbID[c]); } CFdebug << "\n"; cnt += nbEdge; } CFdebug << CFendl; cf_assert( cnt == tot_nb_edges ); CFdebug << RANK << "total nb_edges = " << cnt << CFendl; ) #endif }
XmlNode Protocol::add_reply_frame ( XmlNode& node ) { cf_assert( node.is_valid() ); cf_assert( is_not_null(node.content->parent()) ); rapidxml::xml_node<>* xml_node = node.content; XmlNode replynode = XmlNode(node.content->parent()).add_node( Tags::node_frame()); replynode.set_attribute( "type", Tags::node_type_reply() ); // reply with same target rapidxml::xml_attribute<>* target_att = xml_node->first_attribute("target"); std::string target = is_not_null(target_att) ? target_att->value() : ""; replynode.set_attribute("target", target); // the sender becomes the receiver rapidxml::xml_attribute<>* sender_att = xml_node->first_attribute("sender"); std::string receiver = is_not_null(sender_att) ? sender_att->value() : ""; replynode.set_attribute("receiver", receiver); // same transaction type rapidxml::xml_attribute<>* trans_att = xml_node->first_attribute("transaction"); std::string trans = is_not_null(trans_att) ? trans_att->value() : "auto"; replynode.set_attribute("transaction", trans); // copy uuids, if any rapidxml::xml_attribute<>* client_uuid_att = xml_node->first_attribute( Tags::attr_clientid() ); rapidxml::xml_attribute<>* frame_uuid_att = xml_node->first_attribute( Tags::attr_frameid() ); if( is_not_null(client_uuid_att) ) replynode.set_attribute(Tags::attr_clientid(), client_uuid_att->value()); if( is_not_null(frame_uuid_att) ) replynode.set_attribute(Tags::attr_frameid(), frame_uuid_att->value() ); return replynode; // return XmlNode(); }
void RK::execute() { RDSolver& mysolver = solver().as_type< RDSolver >(); // get the current rk k step and order const Uint rkorder = mysolver.properties().value<Uint>("rkorder"); const Uint step = mysolver.iterative_solver().properties().value<Uint>("iteration"); if (m_solution.expired()) m_solution = mysolver.fields().get_child( RDM::Tags::solution() ).follow()->as_ptr_checked<Field>(); if (m_residual.expired()) m_residual = mysolver.fields().get_child( RDM::Tags::residual() ).follow()->as_ptr_checked<Field>(); if (m_dual_area.expired()) m_dual_area = mysolver.fields().get_child( RDM::Tags::dual_area() ).follow()->as_ptr_checked<Field>(); // get the correct solution to update depending on which rk k step we are Field::Ptr csolution_k; if ( step == rkorder ) csolution_k = m_solution.lock(); else { csolution_k = mysolver.fields().get_child( RDM::Tags::solution() + to_str(step) ).follow()->as_ptr_checked<Field>(); } cf_assert( is_not_null(csolution_k) ); Field& solution_k = *csolution_k; Field& dual_area = *m_dual_area.lock(); Field& residual = *m_residual.lock(); /// @todo should be used later to calculate automatically the \Delta t //const Real CFL = options().option("cfl").value<Real>(); /// @todo maybe better to directly store dual_area inverse // implementation of the RungeKutta update step const Uint nbdofs = solution_k.size(); const Uint nbvars = solution_k.row_size(); for ( Uint i=0; i< nbdofs; ++i ) for ( Uint j=0; j< nbvars; ++j ) solution_k[i][j] += - residual[i][j] / dual_area[i][0]; }
bool SignatureDialog::show(XmlNode & sig, const QString & title, bool block) { cf_assert( sig.is_valid() ); XmlNode node = sig.content->first_node(); QString name; m_okClicked = false; this->setWindowTitle(title); m_dataLayout->clearOptions(); for( ; node.is_valid() ; node.content = node.content->next_sibling()) { m_dataLayout->addOption( SignalOptions::xml_to_option(node) ); name = node.content->first_attribute( Protocol::Tags::attr_key() )->value(); m_nodes[name] = node; } if( m_dataLayout->hasOptions() ) { if(block) { m_isBlocking = true; this->exec(); } else { m_isBlocking = false; this->setModal(true); this->setVisible(true); } } else { m_okClicked = true; emit finished(QDialog::Accepted); } return m_okClicked; }
bool read_dup_res_cb(rw_request* rw) { BENCHMARK_NEXT_DATA_POINT_FROM(rw, read, FROM_CLIENT, dup_res); BENCHMARK_NEXT_DATA_POINT_FROM(rw, batch_sub, FROM_BATCH, dup_res); as_transaction tr; as_transaction_init_from_rw(&tr, rw); if (tr.result_code != AS_OK) { send_read_response(&tr, NULL, NULL, 0, NULL); return true; } if (read_must_ping(&tr)) { // Set up the nodes to which we'll ping. rw->n_dest_nodes = as_partition_get_other_replicas(tr.rsv.p, rw->dest_nodes); if (insufficient_replica_destinations(tr.rsv.ns, rw->n_dest_nodes)) { tr.result_code = AS_ERR_UNAVAILABLE; send_read_response(&tr, NULL, NULL, 0, NULL); return true; } repl_ping_after_dup_res(rw, &tr); return false; } // Read the local copy and respond to origin. transaction_status status = read_local(&tr); cf_assert(status != TRANS_IN_PROGRESS, AS_RW, "read in-progress"); if (status == TRANS_WAITING) { // Note - new tr now owns msgp, make sure rw destructor doesn't free it. // Also, rw will release rsv - new tr will get a new one. rw->msgp = NULL; } // Finished transaction - rw_request cleans up reservation and msgp! return true; }
void increment_solution(const RealVector& solution, const std::vector<std::string>& field_names, const std::vector<std::string>& var_names, const std::vector<Uint>& var_sizes, CMesh& solution_mesh) { const Uint nb_vars = var_names.size(); std::vector<Uint> var_offsets; var_offsets.push_back(0); for(Uint i = 0; i != nb_vars; ++i) { var_offsets.push_back(var_offsets.back() + var_sizes[i]); } // Copy the data to the fields, where each field value is incremented with the value from the solution vector std::set<std::string> unique_field_names; boost_foreach(const std::string& field_name, field_names) { if(unique_field_names.insert(field_name).second) { Field& field = find_component_with_name<Field>(solution_mesh,field_name); const Uint field_size = field.size(); for(Uint row_idx = 0; row_idx != field_size; ++row_idx) { Field::Row row = field[row_idx]; for(Uint i = 0; i != nb_vars; ++i) { if(field_names[i] != field_name) continue; const Uint solution_begin = var_offsets.back() * row_idx + var_offsets[i]; const Uint solution_end = solution_begin + var_sizes[i]; Uint field_idx = field.var_index(var_names[i]); cf_assert( (Uint) field.var_length(var_names[i]) == (Uint) var_sizes[i]); for(Uint sol_idx = solution_begin; sol_idx != solution_end; ++sol_idx) { row[field_idx++] += solution[sol_idx]; } } } } } }
std::string CField::var_name(Uint i) const { cf_assert(i<m_var_types.size()); return m_var_names.size() ? m_var_names[i] : "var"; // std::vector<std::string> names; // switch (m_var_types[i]) // { // case SCALAR: // names += name; // break; // case VECTOR_2D: // names += name+"x"; // names += name+"y"; // break; // case VECTOR_3D: // names += name+"x"; // names += name+"y"; // names += name+"z"; // break; // case TENSOR_2D: // names += name+"xx"; // names += name+"xy"; // names += name+"yx"; // names += name+"yy"; // break; // case TENSOR_3D: // names += name+"xx"; // names += name+"xy"; // names += name+"xz"; // names += name+"yx"; // names += name+"yy"; // names += name+"yz"; // names += name+"zx"; // names += name+"zy"; // names += name+"zz"; // break; // default: // break; // } // return names; }
void repl_ping_cb(rw_request* rw) { BENCHMARK_NEXT_DATA_POINT_FROM(rw, read, FROM_CLIENT, repl_ping); BENCHMARK_NEXT_DATA_POINT_FROM(rw, batch_sub, FROM_BATCH, repl_ping); as_transaction tr; as_transaction_init_from_rw(&tr, rw); // Read the local copy and respond to origin. transaction_status status = read_local(&tr); cf_assert(status != TRANS_IN_PROGRESS, AS_RW, "read in-progress"); if (status == TRANS_WAITING) { // Note - new tr now owns msgp, make sure rw destructor doesn't free it. // Also, rw will release rsv - new tr will get a new one. rw->msgp = NULL; } }
void CField::create_data_storage() { cf_assert( m_var_types.size()!=0 ); cf_assert( is_not_null(m_topology->follow()) ); // Check if there are coordinates in this field, and add to map m_coords = find_parent_component<CMesh>(topology()).nodes().coordinates().as_ptr<CTable<Real> >(); Uint row_size(0); boost_foreach(const VarType var_size, m_var_types) row_size += Uint(var_size); m_data->set_row_size(row_size); switch (m_basis) { case Basis::POINT_BASED: { m_used_nodes = CElements::used_nodes(topology()).as_ptr<CList<Uint> >(); m_data->resize(m_used_nodes->size()); break; } case Basis::ELEMENT_BASED: { Uint data_size = 0; boost_foreach(CEntities& field_elements, find_components_recursively<CEntities>(topology())) { if (field_elements.exists_space(m_space_name) == false) throw ValueNotFound(FromHere(),"space \""+m_space_name+"\" does not exist in "+field_elements.uri().path()); m_elements_start_idx[field_elements.as_ptr<CEntities>()] = data_size; CFieldView field_view("tmp_field_view"); data_size = field_view.initialize(*this,field_elements.as_ptr<CEntities>()); } m_data->resize(data_size); break; } case Basis::CELL_BASED: { Uint data_size = 0; boost_foreach(CEntities& field_elements, find_components_recursively<CCells>(topology())) { //CFinfo << name() << ": creating cellbased field storage in " << field_elements.uri().path() << CFendl; if (field_elements.exists_space(m_space_name) == false) throw ValueNotFound(FromHere(),"space \""+m_space_name+"\" does not exist in "+field_elements.uri().path()); m_elements_start_idx[field_elements.as_ptr<CEntities>()] = data_size; CFieldView field_view("tmp_field_view"); data_size = field_view.initialize(*this,field_elements.as_ptr<CEntities>()); } m_data->resize(data_size); break; } case Basis::FACE_BASED: { Uint data_size = 0; boost_foreach(CEntities& field_elements, find_components_recursively_with_tag<CEntities>(topology(),Mesh::Tags::face_entity())) { if (field_elements.exists_space(m_space_name) == false) throw ValueNotFound(FromHere(),"space \""+m_space_name+"\" does not exist in "+field_elements.uri().path()); m_elements_start_idx[field_elements.as_ptr<CEntities>()] = data_size; CFieldView field_view("tmp_field_view"); data_size = field_view.initialize(*this,field_elements.as_ptr<CEntities>()); } m_data->resize(data_size); break; } default: throw NotSupported(FromHere() , "Basis can only be ELEMENT_BASED or NODE_BASED"); break; } }
void NLog::addException(const QString & message) { cf_assert(!message.isEmpty()); this->appendToLog(LogMessage::EXCEPTION, false, message); }
/* cf_socket_init_svc * Initialize a socket for listening * Leaves the socket in a blocking state - if you want nonblocking, set nonblocking */ int cf_socket_init_svc(cf_socket_cfg *s) { struct timespec delay; cf_assert(s, CF_SOCKET, CF_CRITICAL, "invalid argument"); if (!s->addr) { cf_warning(CF_SOCKET, "could not initialize service, check config file"); return(-1); } if (s->port == 0) { cf_warning(CF_SOCKET, "could not initialize service, missing port, check config file"); return(-1); } delay.tv_sec = 5; delay.tv_nsec = 0; /* Create the socket */ if (0 > (s->sock = socket(AF_INET, s->proto, 0))) { cf_warning(CF_SOCKET, "socket: %s", cf_strerror(errno)); return(-1); } s->saddr.sin_family = AF_INET; if (1 != inet_pton(AF_INET, s->addr, &s->saddr.sin_addr.s_addr)) { cf_warning(CF_SOCKET, "inet_pton: %s", cf_strerror(errno)); return(-1); } s->saddr.sin_port = htons(s->port); if (s->reuse_addr) { int v = 1; setsockopt(s->sock, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v) ); } /* Set close-on-exec */ fcntl(s->sock, F_SETFD, FD_CLOEXEC); // I've tried a little tuning here, doesn't seem terribly important. // int flag = (1024 * 32); // setsockopt(s->sock, SOL_SOCKET, SO_SNDBUF, &flag, sizeof(flag) ); // setsockopt(s->sock, SOL_SOCKET, SO_RCVBUF, &flag, sizeof(flag) ); // No-delay is terribly important, but setting here doesn't seem all that effective. Doesn't // seem to effect the accepted file descriptors derived from the listen fd // int flag = 1; // setsockopt(s->sock, SOL_TCP, TCP_NODELAY, &flag, sizeof(flag) ); /* Bind to the socket; if we can't, nanosleep() and retry */ while (0 > (bind(s->sock, (struct sockaddr *)&s->saddr, sizeof(struct sockaddr)))) { if (EADDRINUSE != errno) { cf_warning(CF_SOCKET, "bind: %s", cf_strerror(errno)); return(-1); } cf_warning(CF_SOCKET, "bind: socket in use, waiting (port:%d)",s->port); nanosleep(&delay, NULL); } /* Listen for connections */ if ((SOCK_STREAM == s->proto) && (0 > listen(s->sock, 512))) { cf_warning(CF_SOCKET, "listen: %s", cf_strerror(errno)); return(-1); } return(0); }
as_namespace * as_namespace_create(char *name, uint16_t replication_factor) { if (strlen(name) >= AS_ID_NAMESPACE_SZ) { cf_warning(AS_NAMESPACE, "can't create namespace: name length too long"); return NULL; } if (replication_factor < 2) { cf_warning(AS_NAMESPACE, "can't create namespace: need replication factor >= 2"); return NULL; } if (g_config.n_namespaces >= AS_NAMESPACE_SZ) { cf_warning(AS_NAMESPACE, "can't create namespace: already have %d", AS_NAMESPACE_SZ); return NULL; } for (int i = 0; i < g_config.n_namespaces; i++) { if (0 == strcmp(g_config.namespaces[i]->name, name)) { cf_warning(AS_NAMESPACE, "can't create namespace: namespace %s mentioned again in the configuration", name); return NULL; } } as_namespace *ns = cf_malloc(sizeof(as_namespace)); cf_assert(ns, AS_NAMESPACE, CF_CRITICAL, "%s as_namespace allocation failed", name); // Set all members 0/NULL/false to start with. memset(ns, 0, sizeof(as_namespace)); strncpy(ns->name, name, AS_ID_NAMESPACE_SZ - 1); ns->name[AS_ID_NAMESPACE_SZ - 1] = '\0'; ns->id = ++g_namespace_id_counter; // note that id is 1-based #ifdef USE_JEM if (-1 == (ns->jem_arena = jem_create_arena())) { cf_crash(AS_NAMESPACE, "can't create JEMalloc arena for namespace %s", name); } else { cf_info(AS_NAMESPACE, "Created JEMalloc arena #%d for namespace \"%s\"", ns->jem_arena, name); } as_namespace_set_jem_arena(ns->name, ns->jem_arena); #endif ns->cold_start = false; // try warm restart unless told not to ns->arena = NULL; // can't create the arena until the configuration has been done //-------------------------------------------- // Configuration defaults. // ns->replication_factor = replication_factor; ns->cfg_replication_factor = replication_factor; ns->memory_size = 1024LL * 1024LL * 1024LL * 4LL; // default memory limit is 4G per namespace ns->default_ttl = 0; // default time-to-live is unlimited ns->enable_xdr = false; ns->sets_enable_xdr = true; // ship all the sets by default ns->ns_forward_xdr_writes = false; // forwarding of xdr writes is disabled by default ns->ns_allow_nonxdr_writes = true; // allow nonxdr writes by default ns->ns_allow_xdr_writes = true; // allow xdr writes by default ns->cold_start_evict_ttl = 0xFFFFffff; // unless this is specified via config file, use evict void-time saved in device header ns->conflict_resolution_policy = AS_NAMESPACE_CONFLICT_RESOLUTION_POLICY_GENERATION; ns->data_in_index = false; ns->evict_tenths_pct = 5; // default eviction amount is 0.5% ns->hwm_disk = 0.5; // default high water mark for eviction is 50% ns->hwm_memory = 0.6; // default high water mark for eviction is 60% ns->ldt_enabled = false; // By default ldt is not enabled ns->ldt_page_size = 8192; // default ldt page size is 8192 ns->ldt_gc_sleep_us = 500; // Default is sleep for .5Ms. This translates to constant 2k Subrecord // GC per second. ns->obj_size_hist_max = OBJ_SIZE_HIST_NUM_BUCKETS; ns->single_bin = false; ns->stop_writes_pct = 0.9; // stop writes when 90% of either memory or disk is used // Set default server policies which are used only when the corresponding override is true: ns->read_consistency_level = AS_POLICY_CONSISTENCY_LEVEL_ONE; ns->read_consistency_level_override = false; ns->write_commit_level = AS_POLICY_COMMIT_LEVEL_ALL; ns->write_commit_level_override = false; ns->storage_type = AS_STORAGE_ENGINE_MEMORY; ns->storage_data_in_memory = true; // Note - default true is consistent with AS_STORAGE_ENGINE_MEMORY, but // cfg.c will set default false for AS_STORAGE_ENGINE_SSD and KV. ns->storage_filesize = 1024LL * 1024LL * 1024LL * 16LL; // default file size is 16G per file ns->storage_scheduler_mode = NULL; // null indicates default is to not change scheduler mode ns->storage_write_block_size = 1024 * 1024; ns->storage_defrag_lwm_pct = 50; // defrag if occupancy of block is < 50% ns->storage_defrag_queue_min = 0; // don't defrag unless the queue has this many eligible wblocks (0: defrag anything queued) ns->storage_defrag_sleep = 1000; // sleep this many microseconds between each wblock ns->storage_defrag_startup_minimum = 10; // defrag until >= 10% disk is writable before joining cluster ns->storage_flush_max_us = 1000 * 1000; // wait this many microseconds before flushing inactive current write buffer (0 = never) ns->storage_fsync_max_us = 0; // fsync interval in microseconds (0 = never) ns->storage_max_write_cache = 1024 * 1024 * 64; ns->storage_min_avail_pct = 5; // stop writes when < 5% disk is writable ns->storage_num_write_blocks = 64; // number of write blocks to use with KV store devices ns->storage_post_write_queue = 256; // number of wblocks per device used as post-write cache ns->storage_read_block_size = 64 * 1024; // size in bytes of read buffers to use with KV store devices // [Note - current FusionIO maximum read buffer size is 1MB - 512B.] ns->storage_write_threads = 1; // SINDEX ns->sindex_data_max_memory = ULONG_MAX; ns->sindex_data_memory_used = 0; ns->sindex_cfg_var_hash = NULL; ns->sindex_num_partitions = DEFAULT_PARTITIONS_PER_INDEX; // Geospatial query within defaults ns->geo2dsphere_within_strict = true; ns->geo2dsphere_within_min_level = 1; ns->geo2dsphere_within_max_level = 30; ns->geo2dsphere_within_max_cells = 12; ns->geo2dsphere_within_level_mod = 1; ns->geo2dsphere_within_earth_radius_meters = 6371000; // Wikipedia, mean // // END - Configuration defaults. //-------------------------------------------- g_config.namespaces[g_config.n_namespaces] = ns; g_config.n_namespaces++; char hist_name[HISTOGRAM_NAME_SIZE]; // Note - histograms' ranges MUST be set before use. sprintf(hist_name, "%s object size histogram", name); ns->obj_size_hist = linear_histogram_create(hist_name, 0, 0, OBJ_SIZE_HIST_NUM_BUCKETS); sprintf(hist_name, "%s evict histogram", name); ns->evict_hist = linear_histogram_create(hist_name, 0, 0, EVICTION_HIST_NUM_BUCKETS); sprintf(hist_name, "%s evict coarse histogram", name); ns->evict_coarse_hist = linear_histogram_create(hist_name, 0, 0, EVICTION_HIST_NUM_BUCKETS); sprintf(hist_name, "%s ttl histogram", name); ns->ttl_hist = linear_histogram_create(hist_name, 0, 0, EVICTION_HIST_NUM_BUCKETS); return ns; }
void as_namespace_eval_write_state(as_namespace *ns, bool *hwm_breached, bool *stop_writes) { cf_assert(ns, AS_NAMESPACE, CF_WARNING, "NULL namespace"); cf_assert(hwm_breached, AS_NAMESPACE, CF_WARNING, "NULL parameter, hwm_breached"); cf_assert(stop_writes, AS_NAMESPACE, CF_WARNING, "NULL parameter, stop_writes"); *hwm_breached = false; *stop_writes = false; // Compute the space limits on this namespace uint64_t mem_lim = ns->memory_size; uint64_t ssd_lim = ns->ssd_size; // Compute the high-watermarks - memory. uint64_t mem_hwm = mem_lim * ns->hwm_memory; uint64_t mem_stop_writes = mem_lim * ns->stop_writes_pct; // Compute the high-watermark - disk. uint64_t ssd_hwm = ssd_lim * ns->hwm_disk; // compute disk size of namespace uint64_t disk_sz = 0; int disk_avail_pct = 0; as_storage_stats(ns, &disk_avail_pct, &disk_sz); // Protection check! Make sure we are not wrapped around for the disk_sz and erroneously evict! if (disk_sz > CL_PETA_BYTES) { cf_warning(AS_NAMESPACE, "namespace disk bytes big %"PRIu64" please bring node down to reset counter", disk_sz); disk_sz = 0; } // Protection check! Make sure we are not wrapped around for the memory counter and erroneously evict! if (cf_atomic_int_get(ns->n_bytes_memory) > CL_TERA_BYTES) { cf_warning(AS_NAMESPACE, "namespace memory bytes big %"PRIu64" please bring node down to reset counter", cf_atomic_int_get(ns->n_bytes_memory)); cf_atomic_int_set(&ns->n_bytes_memory, 0); } // compute memory size of namespace // compute index size - index is always stored in memory uint64_t index_sz = cf_atomic_int_get(ns->n_objects) * as_index_size_get(ns); uint64_t sub_index_sz = cf_atomic_int_get(ns->n_sub_objects) * as_index_size_get(ns); uint64_t sindex_sz = as_sindex_get_ns_memory_used(ns); uint64_t data_in_memory_sz = cf_atomic_int_get(ns->n_bytes_memory); uint64_t memory_sz = index_sz + sub_index_sz + data_in_memory_sz + sindex_sz; // Possible reasons for eviction or stopping writes. // (We don't use all combinations, but in case we change our minds...) static const char* reasons[] = { "", " (memory)", " (disk)", " (memory & disk)", " (disk avail pct)", " (memory & disk avail pct)", " (disk & disk avail pct)", " (all)" }; // check if the high water mark is breached uint32_t how_breached = 0x0; if (memory_sz > mem_hwm) { *hwm_breached = true; how_breached = 0x1; } if (disk_sz > ssd_hwm) { *hwm_breached = true; how_breached |= 0x2; } // check if the writes should be stopped uint32_t why_stopped = 0x0; if (memory_sz > mem_stop_writes) { *stop_writes = true; why_stopped = 0x1; } if (disk_avail_pct < (int)ns->storage_min_avail_pct) { *stop_writes = true; why_stopped |= 0x4; } if (*hwm_breached || *stop_writes) { cf_warning(AS_NAMESPACE, "{%s} hwm_breached %s%s, stop_writes %s%s, memory sz:%"PRIu64" (%"PRIu64" + %"PRIu64") hwm:%"PRIu64" sw:%"PRIu64", disk sz:%"PRIu64" hwm:%"PRIu64, ns->name, *hwm_breached ? "true" : "false", reasons[how_breached], *stop_writes ? "true" : "false", reasons[why_stopped], memory_sz, index_sz, data_in_memory_sz, mem_hwm, mem_stop_writes, disk_sz, ssd_hwm); } else { cf_debug(AS_NAMESPACE, "{%s} hwm_breached %s%s, stop_writes %s%s, memory sz:%"PRIu64" (%"PRIu64" + %"PRIu64") hwm:%"PRIu64" sw:%"PRIu64", disk sz:%"PRIu64" hwm:%"PRIu64, ns->name, *hwm_breached ? "true" : "false", reasons[how_breached], *stop_writes ? "true" : "false", reasons[why_stopped], memory_sz, index_sz, data_in_memory_sz, mem_hwm, mem_stop_writes, disk_sz, ssd_hwm); } }
/* cf_socket_init_client * Connect a socket to a remote endpoint * DOES A BLOCKING CONNECT INLINE - timeout */ int cf_socket_init_client(cf_socket_cfg *s, int timeout) { cf_assert(s, CF_SOCKET, CF_CRITICAL, "invalid argument"); if (0 > (s->sock = socket(AF_INET, s->proto, 0))) { cf_warning(CF_SOCKET, "socket: %s", cf_strerror(errno)); return(-1); } fcntl(s->sock, F_SETFD, FD_CLOEXEC); /* close on exec */ fcntl(s->sock, F_SETFL, O_NONBLOCK); /* non-blocking */ // Try tuning the window: must be done before connect // int flag = (1024 * 32); // setsockopt(s->sock, SOL_SOCKET, SO_SNDBUF, &flag, sizeof(flag) ); // setsockopt(s->sock, SOL_SOCKET, SO_RCVBUF, &flag, sizeof(flag) ); memset(&s->saddr,0,sizeof(s->saddr)); s->saddr.sin_family = AF_INET; int rv = inet_pton(AF_INET, s->addr, &s->saddr.sin_addr.s_addr); if (rv < 0) { cf_warning(CF_SOCKET, "inet_pton: %s", cf_strerror(errno)); close(s->sock); return(-1); } else if (rv == 0) { cf_warning(CF_SOCKET, "inet_pton: invalid ip %s", s->addr); close(s->sock); return(-1); } s->saddr.sin_port = htons(s->port); rv = connect(s->sock, (struct sockaddr *)&s->saddr, sizeof(s->saddr)); cf_debug(CF_SOCKET, "connect: rv %d errno %s",rv,cf_strerror(errno)); if (rv < 0) { int epoll_fd = -1; if (errno == EINPROGRESS) { cf_clock start = cf_getms(); if (0 > (epoll_fd = epoll_create(1))) { cf_warning(CF_SOCKET, "epoll_create() failed (errno %d: \"%s\")", errno, cf_strerror(errno)); goto Fail; } struct epoll_event event; memset(&event, 0, sizeof(struct epoll_event)); event.data.fd = s->sock; event.events = EPOLLOUT; if (0 > epoll_ctl(epoll_fd, EPOLL_CTL_ADD, s->sock, &event)) { cf_warning(CF_SOCKET, "epoll_ctl(ADD) of client socket failed (errno %d: \"%s\")", errno, cf_strerror(errno)); goto Fail; } int tries = 0; do { int nevents = 0; int max_events = 1; int wait_ms = 1; struct epoll_event events[max_events]; if (0 > (nevents = epoll_wait(epoll_fd, events, max_events, wait_ms))) { if (errno == EINTR) { cf_debug(CF_SOCKET, "epoll_wait() on client socket encountered EINTR ~~ Retrying!"); goto Retry; } else { cf_warning(CF_SOCKET, "epoll_wait() on client socket failed (errno %d: \"%s\") ~~ Failing!", errno, cf_strerror(errno)); goto Fail; } } else { if (nevents == 0) { cf_debug(CF_SOCKET, "epoll_wait() returned no events ~~ Retrying!"); goto Retry; } if (nevents != 1) { cf_warning(CF_SOCKET, "epoll_wait() returned %d events ~~ only 1 expected, so ignoring others!", nevents); } if (events[0].data.fd == s->sock) { if (events[0].events & EPOLLOUT) { cf_debug(CF_SOCKET, "epoll_wait() on client socket ready for write detected ~~ Succeeding!"); } else { // (Note: ERR and HUP events are automatically waited for as well.) if (events[0].events & (EPOLLERR | EPOLLHUP)) { cf_debug(CF_SOCKET, "epoll_wait() on client socket detected failure event 0x%x ~~ Failing!", events[0].events); } else { cf_warning(CF_SOCKET, "epoll_wait() on client socket detected non-write events 0x%x ~~ Failing!", events[0].events); } goto Fail; } } else { cf_warning(CF_SOCKET, "epoll_wait() on client socket returned event on unknown socket %d ~~ Retrying!", events[0].data.fd); goto Retry; } if (0 > epoll_ctl(epoll_fd, EPOLL_CTL_DEL, s->sock, &event)) { cf_warning(CF_SOCKET, "epoll_ctl(DEL) on client socket failed (errno %d: \"%s\")", errno, cf_strerror(errno)); } close(epoll_fd); goto Success; } Retry: cf_debug(CF_SOCKET, "Connect epoll loop: Retry #%d", tries++); if (start + timeout < cf_getms()) { cf_warning(CF_SOCKET, "Error in delayed connect() to %s:%d: timed out", s->addr, s->port); errno = ETIMEDOUT; goto Fail; } } while (1); } Fail: cf_debug(CF_SOCKET, "connect failed to %s:%d : %s", s->addr, s->port, cf_strerror(errno)); if (epoll_fd > 0) { close(epoll_fd); } close(s->sock); s->sock = -1; return(-1); } else { cf_debug(CF_SOCKET, "client socket connect() to %s:%d in 1 try!", s->addr, s->port); } Success: ; // regarding this: calling here doesn't seem terribly effective. // on the fabric threads, it seems important to set no-delay much later int flag = 1; setsockopt(s->sock, SOL_TCP, TCP_NODELAY, &flag, sizeof(flag)); long farg = fcntl(s->sock, F_GETFL, 0); fcntl(s->sock, F_SETFL, farg & (~O_NONBLOCK)); /* blocking again */ return(0); }