本文整理汇总了C++中work函数的典型用法代码示例。如果您正苦于以下问题:C++ work函数的具体用法?C++ work怎么用?C++ work使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了work函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: num_threads
void S<T>::test()
{
#pragma omp parallel num_threads(n) // { dg-error "must be integral" }
work();
}
示例2: cloud_in
/*
* Receive callback for the /camera/depth_registered/points subscription
*/
std::vector<suturo_perception_msgs::PerceivedObject> SuturoPerceptionKnowledgeROSNode::receive_image_and_cloud(const sensor_msgs::ImageConstPtr& inputImage, const sensor_msgs::PointCloud2ConstPtr& inputCloud)
{
// process only one cloud
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_in (new pcl::PointCloud<pcl::PointXYZRGB>());
pcl::fromROSMsg(*inputCloud,*cloud_in);
logger.logInfo((boost::format("Received a new point cloud: size = %s") % cloud_in->points.size()).str());
// Gazebo sends us unorganized pointclouds!
// Reorganize them to be able to compute the ROI of the objects
// This workaround is only tested for gazebo 1.9!
if(!cloud_in->isOrganized ())
{
logger.logInfo((boost::format("Received an unorganized PointCloud: %d x %d .Convert it to a organized one ...") % cloud_in->width % cloud_in->height ).str());
pcl::PointCloud<pcl::PointXYZRGB>::Ptr org_cloud (new pcl::PointCloud<pcl::PointXYZRGB>());
org_cloud->width = 640;
org_cloud->height = 480;
org_cloud->is_dense = false;
org_cloud->points.resize(640 * 480);
for (int i = 0; i < cloud_in->points.size(); i++) {
pcl::PointXYZRGB result;
result.x = 0;
result.y = 0;
result.z = 0;
org_cloud->points[i]=cloud_in->points[i];
}
cloud_in = org_cloud;
}
cv_bridge::CvImagePtr cv_ptr;
cv_ptr = cv_bridge::toCvCopy(inputImage, enc::BGR8);
// Make a deep copy of the passed cv::Mat and set a new
// boost pointer to it.
boost::shared_ptr<cv::Mat> img(new cv::Mat(cv_ptr->image.clone()));
sp.setOriginalRGBImage(img);
logger.logInfo("processing...");
sp.setOriginalCloud(cloud_in);
sp.processCloudWithProjections(cloud_in);
logger.logInfo("Cloud processed. Lock buffer and return the results");
mutex.lock();
perceivedObjects = sp.getPerceivedObjects();
if(sp.getOriginalRGBImage()->cols != sp.getOriginalCloud()->width
&& sp.getOriginalRGBImage()->rows != sp.getOriginalCloud()->height)
{
// Adjust the ROI if the image is at 1280x1024 and the pointcloud is at 640x480
if(sp.getOriginalRGBImage()->cols == 1280 && sp.getOriginalRGBImage()->rows == 1024)
{
for (int i = 0; i < perceivedObjects.size(); i++) {
ROI roi = perceivedObjects.at(i).get_c_roi();
roi.origin.x*=2;
roi.origin.y*=2;
roi.width*=2;
roi.height*=2;
perceivedObjects.at(i).set_c_roi(roi);
}
}
else
{
logger.logError("UNSUPPORTED MIXTURE OF IMAGE AND POINTCLOUD DIMENSIONS");
}
}
// Execution pipeline
// Each capability provides an enrichment for the
// returned PerceivedObject
// initialize threadpool
boost::asio::io_service ioService;
boost::thread_group threadpool;
std::auto_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(ioService));
// Add worker threads to threadpool
for(int i = 0; i < numThreads; ++i)
{
threadpool.create_thread(
boost::bind(&boost::asio::io_service::run, &ioService)
);
}
for (int i = 0; i < perceivedObjects.size(); i++)
{
// Initialize Capabilities
ColorAnalysis ca(perceivedObjects[i]);
ca.setLowerSThreshold(color_analysis_lower_s);
ca.setUpperSThreshold(color_analysis_upper_s);
ca.setLowerVThreshold(color_analysis_lower_v);
ca.setUpperVThreshold(color_analysis_upper_v);
suturo_perception_shape_detection::RandomSampleConsensus sd(perceivedObjects[i]);
//suturo_perception_vfh_estimation::VFHEstimation vfhe(perceivedObjects[i]);
// suturo_perception_3d_capabilities::CuboidMatcherAnnotator cma(perceivedObjects[i]);
// Init the cuboid matcher with the table coefficients
//.........这里部分代码省略.........
示例3: main
int main()
{
init();
work();
return 0;
}
示例4: HibernateBoot
void HibernateBoot(char *image_filename)
{
long long size, imageSize, codeSize, allocSize;
long mem_base;
IOHibernateImageHeader _header;
IOHibernateImageHeader * header = &_header;
long buffer;
size = ReadFileAtOffset (image_filename, header, 0, sizeof(IOHibernateImageHeader));
printf("header read size %x\n", size);
imageSize = header->image1Size;
codeSize = header->restore1PageCount << 12;
if (kIOHibernateHeaderSignature != header->signature)
{
printf ("Incorrect image signature\n");
return;
}
if (header->encryptStart)
{
printf ("Resuming from Encrypted image is unsupported.\n"
"Uncheck \"Use secure virtual memory\" in \"Security\" pane on system preferences.\n"
"Press any key to proceed with normal boot.\n");
getc ();
return;
}
// depends on NVRAM
#if 0
{
uint32_t machineSignature;
size = GetProp(gChosenPH, kIOHibernateMachineSignatureKey,
(char *)&machineSignature, sizeof(machineSignature));
if (size != sizeof(machineSignature)) machineSignature = 0;
if (machineSignature != header->machineSignature)
break;
}
#endif
allocSize = imageSize + ((4095 + sizeof(hibernate_graphics_t)) & ~4095);
mem_base = getmemorylimit() - allocSize;//TODO: lower this
printf("mem_base %x\n", mem_base);
if (!((long long)mem_base+allocSize<1024*bootInfo->extmem+0x100000))
{
printf ("Not enough space to restore image. Press any key to proceed with normal boot.\n");
getc ();
return;
}
bcopy(header, (void *) mem_base, sizeof(IOHibernateImageHeader));
header = (IOHibernateImageHeader *) mem_base;
imageSize -= sizeof(IOHibernateImageHeader);
buffer = (long)(header + 1);
if (header->previewSize)
{
uint64_t preview_offset = header->fileExtentMapSize - sizeof(header->fileExtentMap) + codeSize;
uint8_t progressSaveUnder[kIOHibernateProgressCount][kIOHibernateProgressSaveUnderSize];
ReadFileAtOffset (image_filename, (char *)buffer, sizeof(IOHibernateImageHeader), preview_offset+header->previewSize);
drawPreview ((void *)(long)(buffer+preview_offset + header->previewPageListSize), &(progressSaveUnder[0][0]));
previewTotalSectors = (imageSize-(preview_offset+header->previewSize))/512;
previewLoadedSectors = 0;
previewSaveunder = &(progressSaveUnder[0][0]);
if (preview_offset+header->previewSize<imageSize)
ReadFileAtOffset (image_filename, (char *)(long)(buffer+preview_offset+header->previewSize),
sizeof(IOHibernateImageHeader)+preview_offset+header->previewSize,
imageSize-(preview_offset+header->previewSize));
previewTotalSectors = 0;
previewLoadedSectors = 0;
previewSaveunder = 0;
#if 0
AsereBLN:
check_vga_nvidia() didn't work as expected (recursion level > 0 & return value).
Unforutnaltely I cannot find a note why to switch back to text mode for nVidia cards only
and because it check_vga_nvidia does not work (cards normally are behind a bridge) I will
remove it completely
setVideoMode( VGA_TEXT_MODE, 0 );
#endif
}
示例5: new_work_agg
// a new aggregate is to be inserted into the work queue
inline void new_work_agg(db::node *node, db::simple_tuple *stpl)
{
process::work work(node, stpl, process::mods::LOCAL_TUPLE | process::mods::FORCE_AGGREGATE);
new_agg(work);
}
示例6: GetNcoeffs
//.........这里部分代码省略.........
/// we simulate the multiplication by the identity matrix.
/// The results stored in outarray is one of the columns of the weak advection oprators
/// which are then stored in MATRIX for the futher eigenvalues calculation.
switch (m_projectionType)
{
case MultiRegions::eDiscontinuous:
{
WeakDGAdvection(inarray, WeakAdv,true,true,1);
m_fields[0]->MultiplyByElmtInvMass(WeakAdv[0],WeakAdv[0]);
m_fields[0]->BwdTrans(WeakAdv[0],outarray[0]);
Vmath::Neg(npoints,outarray[0],1);
break;
}
case MultiRegions::eGalerkin:
case MultiRegions::eMixed_CG_Discontinuous:
{
// Calculate -V\cdot Grad(u);
for(i = 0; i < nvariables; ++i)
{
//Projection
m_fields[i]->FwdTrans(inarray[i],WeakAdv[i]);
m_fields[i]->BwdTrans_IterPerExp(WeakAdv[i],tmp[i]);
//Advection operator
AdvectionNonConservativeForm(m_velocity,tmp[i],outarray[i]);
Vmath::Neg(npoints,outarray[i],1);
//m_fields[i]->MultiplyByInvMassMatrix(WeakAdv[i],WeakAdv[i]);
//Projection
m_fields[i]->FwdTrans(outarray[i],WeakAdv[i]);
m_fields[i]->BwdTrans_IterPerExp(WeakAdv[i],outarray[i]);
}
break;
}
}
/// The result is stored in outarray (is the j-th columns of the weak advection operator).
/// We now store it in MATRIX(j)
Vmath::Vcopy(npoints,&(outarray[0][0]),1,&(MATRIX[j]),npoints);
/// Set the j-th entry of inarray back to zero
inarray[0][j] = 0.0;
}
////////////////////////////////////////////////////////////////////////////////
/// Calulating the eigenvalues of the weak advection operator stored in (MATRIX)
/// using Lapack routines
char jobvl = 'N';
char jobvr = 'N';
int info = 0, lwork = 3*npoints;
NekDouble dum;
Array<OneD, NekDouble> EIG_R(npoints);
Array<OneD, NekDouble> EIG_I(npoints);
Array<OneD, NekDouble> work(lwork);
Lapack::Dgeev(jobvl,jobvr,npoints,MATRIX.get(),npoints,EIG_R.get(),EIG_I.get(),&dum,1,&dum,1,&work[0],lwork,info);
////////////////////////////////////////////////////////
//Print Matrix
FILE *mFile;
mFile = fopen ("WeakAdvMatrix.txt","w");
for(int j = 0; j<npoints; j++)
{
for(int k = 0; k<npoints; k++)
{
fprintf(mFile,"%e ",MATRIX[j*npoints+k]);
}
fprintf(mFile,"\n");
}
fclose (mFile);
////////////////////////////////////////////////////////
//Output of the EigenValues
FILE *pFile;
pFile = fopen ("Eigenvalues.txt","w");
for(int j = 0; j<npoints; j++)
{
fprintf(pFile,"%e %e\n",EIG_R[j],EIG_I[j]);
}
fclose (pFile);
cout << "\nEigenvalues : " << endl;
for(int j = 0; j<npoints; j++)
{
cout << EIG_R[j] << "\t" << EIG_I[j] << endl;
}
cout << endl;
}
示例7: main
int main()
{
while (work());
return 0;
}
示例8: fscanf
void Solve::solve(FILE *fin, FILE *fout)
{
int cnt = 1;
for(int i = 0; i <= 10; i ++, cnt *= 2)
lb[cnt] = i;
fscanf(fin, "%d%d", &n, &m);
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
fscanf(fin, "%d", &object[i][j].a);
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
fscanf(fin, "%d", &object[i][j].d);
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
fscanf(fin, "%d", &object[i][j].hp);
fscanf(fin, "%d%d%d", &llx.a, &llx.d, &llx.hp);
fscanf(fin, "%d", &nBaby);
for(int i = 1; i <= nBaby; i ++)
fscanf(fin, "%d%d%d", &baby[i].a, &baby[i].d, &baby[i].hp);
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
{
Stuff &lyd = object[i][j];
if(llx.a <= lyd.d)
w[i][j][0] = INFINITY;
else
{
int t1 = ceilDiv(lyd.hp, llx.a-lyd.d);
int tmp = (t1 - 1) * MAX(0, lyd.a - llx.d);
if(tmp >= llx.hp)
w[i][j][0] = INFINITY;
else
w[i][j][0] = tmp;
}
for(int k = 1; k <= nBaby; k ++)
{
Stuff &bb = baby[k];
if(bb.a <= lyd.d)
w[i][j][k] = INFINITY;
else
{
int t1 = ceilDiv(lyd.hp, bb.a - lyd.d);
int tmp = (t1 - 1) * MAX(0, lyd.a - bb.d);
if(tmp >= bb.hp)
{
int t2 = ceilDiv(bb.hp, lyd.a - bb.d);
tmp = t2 * MAX(0, bb.a - lyd.d);
//baby died
if(llx.a <= lyd.d)
w[i][j][k] = INFINITY;
else
{
int t1 = ceilDiv(lyd.hp - tmp, llx.a-lyd.d);
tmp = (t1 - 1) * MAX(0, lyd.a - llx.d);
if(tmp >= llx.hp)
w[i][j][k] = INFINITY;
else
w[i][j][k] = tmp;
}
}
else
w[i][j][k] = 0;
}
}
}
upperlim = (1 << nBaby) - 1;
work(fin, fout);
}
示例9: main
int main(int argc, char **argv){
// Add some plugin searhc paths
plugin_search_path=list_new(free);
const char *infilename=NULL;
const char *outfilename=NULL;
char tmp[256];
char *assetfilename="assets.h";
int i;
for (i=1;i<argc;i++){
if (strcmp(argv[i], "--help")==0){
help(NULL);
return 0;
}
else if ((strcmp(argv[i], "--templatetagsdir")==0) || (strcmp(argv[i], "-t")==0)){
i++;
if (argc<=i){
help("Missing templatedir name");
return 3;
}
snprintf(tmp, sizeof(tmp), "%s/lib%%s.so", argv[i]);
ONION_DEBUG("Added templatedir %s", tmp);
list_add(plugin_search_path, strdup(tmp)); // dup, remember to free later.
}
else if ((strcmp(argv[i], "--no-orig-lines")==0) || (strcmp(argv[i], "-n")==0)){
use_orig_line_numbers=0;
ONION_DEBUG("Disable original line numbers");
}
else if ((strcmp(argv[i], "--asset-file")==0) || (strcmp(argv[i], "-a")==0)){
i++;
if (argc<=i){
help("Missing assets file name");
return 3;
}
assetfilename=argv[i];
ONION_DEBUG("Assets file: %s", assetfilename);
}
else{
if (infilename){
if (outfilename){
help("Too many arguments");
return 1;
}
outfilename=argv[i];
ONION_DEBUG("Set outfilename %s", outfilename);
}
else{
infilename=argv[i];
ONION_DEBUG("Set infilename %s", infilename);
}
}
}
if (!infilename || !outfilename){
help("Missing input or output filename");
return 2;
}
if (strcmp(infilename,"-")==0){
infilename="";
}
else{
char tmp2[256];
strncpy(tmp2, argv[1], sizeof(tmp2)-1);
snprintf(tmp, sizeof(tmp), "%s/lib%%s.so", dirname(tmp2));
list_add(plugin_search_path, strdup(tmp));
strncpy(tmp2, argv[1], sizeof(tmp2)-1);
snprintf(tmp, sizeof(tmp), "%s/templatetags/lib%%s.so", dirname(tmp2));
list_add(plugin_search_path, strdup(tmp));
}
// Default template dirs
list_add_with_flags(plugin_search_path, "lib%s.so", LIST_ITEM_NO_FREE);
list_add_with_flags(plugin_search_path, "templatetags/lib%s.so", LIST_ITEM_NO_FREE);
char tmp2[256];
strncpy(tmp2, argv[0], sizeof(tmp2)-1);
snprintf(tmp, sizeof(tmp), "%s/templatetags/lib%%s.so", dirname(tmp2));
list_add(plugin_search_path, strdup(tmp)); // dupa is ok, as im at main.
strncpy(tmp2, argv[0], sizeof(tmp2)-1);
snprintf(tmp, sizeof(tmp), "%s/lib%%s.so", dirname(tmp2));
list_add(plugin_search_path, strdup(tmp)); // dupa is ok, as im at main.
list_add_with_flags(plugin_search_path, "/usr/local/lib/otemplate/templatetags/lib%s.so", LIST_ITEM_NO_FREE);
list_add_with_flags(plugin_search_path, "/usr/lib/otemplate/templatetags/lib%s.so", LIST_ITEM_NO_FREE);
onion_assets_file *assetsfile=onion_assets_file_new(assetfilename);
int error=work(infilename, outfilename, assetsfile);
onion_assets_file_free(assetsfile);
list_free(plugin_search_path);
return error;
}
示例10: main
//.........这里部分代码省略.........
{
schema_registrys.push_back(csi::kafka::broker_address(i->host_name, schema_registry_port));
}
}
// right now the schema registry class cannot handle severel hosts so just stick to the first one.
used_schema_registry = schema_registrys[0].host_name + ":" + std::to_string(schema_registrys[0].port);
std::string kafka_broker_str = "";
for (std::vector<csi::kafka::broker_address>::const_iterator i = kafka_brokers.begin(); i != kafka_brokers.end(); ++i)
{
kafka_broker_str += i->host_name + ":" + std::to_string(i->port);
if (i != kafka_brokers.end() - 1)
kafka_broker_str += ", ";
}
BOOST_LOG_TRIVIAL(info) << "kafka broker(s): " << kafka_broker_str;
BOOST_LOG_TRIVIAL(info) << "topic : " << topic;
std::string schema_registrys_info;
for (std::vector<csi::kafka::broker_address>::const_iterator i = schema_registrys.begin(); i != schema_registrys.end(); ++i)
{
schema_registrys_info += i->host_name + ":" + std::to_string(i->port);
if (i != schema_registrys.end() - 1)
schema_registrys_info += ", ";
}
BOOST_LOG_TRIVIAL(info) << "schema_registry(s) : " << schema_registrys_info;
BOOST_LOG_TRIVIAL(info) << "used schema registry: " << used_schema_registry;
int64_t total = 0;
boost::asio::io_service fg_ios;
std::auto_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(fg_ios));
boost::thread fg(boost::bind(&boost::asio::io_service::run, &fg_ios));
csi::kafka::highlevel_producer producer(fg_ios, topic, -1, 200, 1000000);
confluent::registry registry(fg_ios, used_schema_registry);
confluent::codec avro_codec(registry);
producer.connect(kafka_brokers);
BOOST_LOG_TRIVIAL(info) << "connected to kafka";
producer.connect_forever(kafka_brokers);
boost::thread do_log([&producer]
{
while (true)
{
boost::this_thread::sleep(boost::posix_time::seconds(1));
std::vector<csi::kafka::highlevel_producer::metrics> metrics = producer.get_metrics();
size_t total_queue = 0;
uint32_t tx_msg_sec_total = 0;
uint32_t tx_kb_sec_total = 0;
for (std::vector<csi::kafka::highlevel_producer::metrics>::const_iterator i = metrics.begin(); i != metrics.end(); ++i)
{
total_queue += (*i).msg_in_queue;
tx_msg_sec_total += (*i).tx_msg_sec;
tx_kb_sec_total += (*i).tx_kb_sec;
}
BOOST_LOG_TRIVIAL(info) << "\t \tqueue:" << total_queue << "\t" << tx_msg_sec_total << " msg/s \t" << (tx_kb_sec_total / 1024) << "MB/s";
}
});
示例11: main
int main()
{
read();
work();
return 0;
}
示例12: Basis_HGRAD_LINE_Cn_FEM
Basis_HGRAD_LINE_Cn_FEM<SpT,OT,PT>::
Basis_HGRAD_LINE_Cn_FEM( const ordinal_type order,
const EPointType pointType ) {
this->basisCardinality_ = order+1;
this->basisDegree_ = order;
this->basisCellTopology_ = shards::CellTopology(shards::getCellTopologyData<shards::Line<2> >() );
this->basisType_ = BASIS_FEM_FIAT;
this->basisCoordinates_ = COORDINATES_CARTESIAN;
const ordinal_type card = this->basisCardinality_;
// points are computed in the host and will be copied
Kokkos::DynRankView<typename scalarViewType::value_type,typename SpT::array_layout,Kokkos::HostSpace>
dofCoords("Hgrad::Line::Cn::dofCoords", card, 1);
switch (pointType) {
case POINTTYPE_EQUISPACED:
case POINTTYPE_WARPBLEND: {
// lattice ordering
{
const ordinal_type offset = 0;
PointTools::getLattice( dofCoords,
this->basisCellTopology_,
order, offset,
pointType );
}
// topological order
// {
// // two vertices
// dofCoords(0,0) = -1.0;
// dofCoords(1,0) = 1.0;
// // internal points
// typedef Kokkos::pair<ordinal_type,ordinal_type> range_type;
// auto pts = Kokkos::subview(dofCoords, range_type(2, card), Kokkos::ALL());
// const auto offset = 1;
// PointTools::getLattice( pts,
// this->basisCellTopology_,
// order, offset,
// pointType );
// }
break;
}
case POINTTYPE_GAUSS: {
// internal points only
PointTools::getGaussPoints( dofCoords,
order );
break;
}
default: {
INTREPID2_TEST_FOR_EXCEPTION( !isValidPointType(pointType),
std::invalid_argument ,
">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM) invalid pointType." );
}
}
this->dofCoords_ = Kokkos::create_mirror_view(typename SpT::memory_space(), dofCoords);
Kokkos::deep_copy(this->dofCoords_, dofCoords);
// form Vandermonde matrix; actually, this is the transpose of the VDM,
// this matrix is used in LAPACK so it should be column major and left layout
const ordinal_type lwork = card*card;
Kokkos::DynRankView<typename scalarViewType::value_type,Kokkos::LayoutLeft,Kokkos::HostSpace>
vmat("Hgrad::Line::Cn::vmat", card, card),
work("Hgrad::Line::Cn::work", lwork),
ipiv("Hgrad::Line::Cn::ipiv", card);
const double alpha = 0.0, beta = 0.0;
Impl::Basis_HGRAD_LINE_Cn_FEM_JACOBI::
getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>
(vmat, dofCoords, order, alpha, beta, OPERATOR_VALUE);
ordinal_type info = 0;
Teuchos::LAPACK<ordinal_type,typename scalarViewType::value_type> lapack;
lapack.GETRF(card, card,
vmat.data(), vmat.stride_1(),
(ordinal_type*)ipiv.data(),
&info);
INTREPID2_TEST_FOR_EXCEPTION( info != 0,
std::runtime_error ,
">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM) lapack.GETRF returns nonzero info." );
lapack.GETRI(card,
vmat.data(), vmat.stride_1(),
(ordinal_type*)ipiv.data(),
work.data(), lwork,
&info);
INTREPID2_TEST_FOR_EXCEPTION( info != 0,
std::runtime_error ,
">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM) lapack.GETRI returns nonzero info." );
// create host mirror
Kokkos::DynRankView<typename scalarViewType::value_type,typename SpT::array_layout,Kokkos::HostSpace>
vinv("Hgrad::Line::Cn::vinv", card, card);
//.........这里部分代码省略.........
示例13: BCs
void PBCmgr::maintain (const int_t step ,
const Field* P ,
const AuxField** Us ,
const AuxField** Uf ,
const bool timedep)
// ---------------------------------------------------------------------------
// Update storage for evaluation of high-order pressure boundary
// condition. Storage order for each edge represents a CCW traverse
// of element boundaries.
//
// If the velocity field varies in time on HOPB field boundaries
// (e.g. due to time-varying BCs) the local fluid acceleration will be
// estimated from input velocity fields by explicit extrapolation if
// timedep is true. This correction cannot be carried out at the
// first timestep, since the required extrapolation cannot be done.
// If the acceleration is known, (for example, a known reference frame
// acceleration) it is probably better to leave timedep unset, and to
// use PBCmgr::accelerate() to add in the accelerative term. Note
// also that since grad P is dotted with n, the unit outward normal,
// at a later stage, timedep only needs to be set if there are
// wall-normal accelerative terms. NB: The default value of timedep
// is 1.
//
// Field* master gives a list of pressure boundary conditions with
// which to traverse storage areas (note this assumes equal-order
// interpolations).
//
// No smoothing is done to high-order spatial derivatives computed here.
// ---------------------------------------------------------------------------
{
const real_t nu = Femlib::value ("KINVIS");
const real_t invDt = 1.0 / Femlib::value ("D_T");
const int_t nTime = Femlib::ivalue ("N_TIME");
const int_t nEdge = P -> _nbound;
const int_t nZ = P -> _nz;
const int_t nP = Geometry::nP();
const int_t base = Geometry::baseMode();
const int_t nMode = Geometry::nModeProc();
const int_t mLo = (Geometry::procID() == 0) ? 1 : 0;
const AuxField* Ux = Us[0];
const AuxField* Uy = Us[1];
const AuxField* Uz = (nZ > 1) ? Us[2] : 0;
const AuxField* Nx = Uf[0];
const AuxField* Ny = Uf[1];
const vector<Boundary*>& BC = P -> _bsys -> BCs (0);
register Boundary* B;
register int_t i, k, q;
int_t m, offset, skip, Je;
// -- Roll grad P storage area up, load new level of nonlinear terms Uf.
rollv (_Pnx, nTime);
rollv (_Pny, nTime);
for (i = 0; i < nEdge; i++) {
B = BC[i];
offset = B -> dOff ();
skip = B -> dSkip();
for (k = 0; k < nZ; k++) {
ROOTONLY if (k == 1) continue;
Veclib::copy (nP, Nx -> _plane[k] + offset, skip, _Pnx[0][i][k], 1);
Veclib::copy (nP, Ny -> _plane[k] + offset, skip, _Pny[0][i][k], 1);
// -- For cylindrical coordinates, N_ are radius-premultiplied. Cancel.
if (Geometry::cylindrical()) {
B -> divY (_Pnx[0][i][k]);
B -> divY (_Pny[0][i][k]);
}
}
}
// -- Add in -nu * curl curl u.
vector<real_t> work (5 * sqr(nP) + 7 * nP + Integration::OrderMax + 1);
real_t *UxRe, *UxIm, *UyRe, *UyIm, *UzRe, *UzIm, *tmp;
real_t* wrk = &work[0];
real_t* xr = wrk + 5*sqr(nP) + 3*nP;
real_t* xi = xr + nP;
real_t* yr = xi + nP;
real_t* yi = yr + nP;
real_t* alpha = yi + nP;
for (i = 0; i < nEdge; i++) {
B = BC[i];
offset = B -> dOff ();
skip = B -> dSkip();
ROOTONLY { // -- Deal with 2D/zero Fourier mode terms.
UxRe = Ux -> _plane[0];
UyRe = Uy -> _plane[0];
B -> curlCurl (0,UxRe,0,UyRe,0,0,0,xr,0,yr,0,wrk);
Blas::axpy (nP, -nu, xr, 1, _Pnx[0][i][0], 1);
Blas::axpy (nP, -nu, yr, 1, _Pny[0][i][0], 1);
//.........这里部分代码省略.........
示例14: work
void
o3d3xx::FrameGrabber::Run()
{
boost::asio::io_service::work work(this->io_service_);
//
// setup the camera for image acquistion
//
std::string cam_ip;
int cam_port;
try
{
cam_ip = this->cam_->GetIP();
cam_port = std::stoi(this->cam_->GetParameter("PcicTcpPort"));
}
catch (const o3d3xx::error_t& ex)
{
LOG(ERROR) << "Could not get IP/Port of the camera: "
<< ex.what();
return;
}
LOG(INFO) << "Camera connection info: ip=" << cam_ip
<< ", port=" << cam_port;
try
{
this->cam_->RequestSession();
this->cam_->SetOperatingMode(o3d3xx::Camera::operating_mode::RUN);
this->cam_->CancelSession();
}
catch (const o3d3xx::error_t& ex)
{
LOG(ERROR) << "Failed to setup camera for image acquisition: "
<< ex.what();
return;
}
//
// init the asio structures
//
boost::asio::ip::tcp::socket sock(this->io_service_);
boost::asio::ip::tcp::endpoint endpoint(
boost::asio::ip::address::from_string(cam_ip), cam_port);
//
// Forward declare our read handlers (because they need to call
// eachother).
//
o3d3xx::FrameGrabber::WriteHandler result_schema_write_handler;
o3d3xx::FrameGrabber::ReadHandler ticket_handler;
o3d3xx::FrameGrabber::ReadHandler image_handler;
//
// image data callback
//
std::size_t bytes_read = 0;
std::size_t buff_sz = 0; // bytes
image_handler =
[&, this]
(const boost::system::error_code& ec, std::size_t bytes_transferred)
{
if (ec) { throw o3d3xx::error_t(ec.value()); }
bytes_read += bytes_transferred;
//DLOG(INFO) << "Read " << bytes_read << " image bytes of "
// << buff_sz;
if (bytes_read == buff_sz)
{
DLOG(INFO) << "Got full image!";
bytes_read = 0;
// 1. verify the data
if (o3d3xx::verify_image_buffer(this->back_buffer_))
{
DLOG(INFO) << "Image OK";
// 2. move the data to the front buffer in O(1) time complexity
this->front_buffer_mutex_.lock();
this->back_buffer_.swap(this->front_buffer_);
this->front_buffer_mutex_.unlock();
// 3. notify waiting clients
this->front_buffer_cv_.notify_all();
}
else
{
LOG(WARNING) << "Bad image!";
}
// read another ticket
sock.async_read_some(
boost::asio::buffer(this->ticket_buffer_.data(),
o3d3xx::IMG_TICKET_SZ),
ticket_handler);
return;
}
//.........这里部分代码省略.........
示例15: main
int main(int argc, char *argv[])
{
const char *url;
int i, threads;
pthread_t *t;
int *args;
lList *answer_list = NULL;
lListElem *spooling_context;
DENTER_MAIN(TOP_LAYER, "test_berkeleydb_mt");
/* parse commandline parameters */
if (argc < 3) {
ERROR((SGE_EVENT, "usage: test_berkeleydb_mt <url> <threads> [<delay>]\n"));
ERROR((SGE_EVENT, " <url> = path or host:database\n"));
ERROR((SGE_EVENT, " <threads> = number of threads\n"));
ERROR((SGE_EVENT, " <delay> = delay after writing [ms]\n"));
SGE_EXIT(NULL, 1);
}
url = argv[1];
threads = atoi(argv[2]);
if (argc > 3) {
delay = atoi(argv[3]);
}
/* allocate memory for pthreads and arguments */
t = (pthread_t *)malloc(threads * sizeof(pthread_t));
args = (int *)malloc(threads * sizeof(int));
DPRINTF(("writing to database %s from %d threads\n", url, threads));
/* initialize spooling */
spooling_context = spool_create_dynamic_context(&answer_list, NULL, url, NULL);
answer_list_output(&answer_list);
if (spooling_context == NULL) {
SGE_EXIT(NULL, EXIT_FAILURE);
}
spool_set_default_context(spooling_context);
if (!spool_startup_context(&answer_list, spooling_context, true)) {
answer_list_output(&answer_list);
SGE_EXIT(NULL, EXIT_FAILURE);
}
answer_list_output(&answer_list);
/* let n threads to parallel spooling */
for (i = 0; i < threads; i++) {
args[i] = i + 1;
pthread_create(&(t[i]), NULL, work, (void*)(&args[i]));
}
/* also work in current thread */
work((void *)0);
/* wait for termination of all threads */
for (i = 0; i < threads; i++) {
pthread_join(t[i], NULL);
}
/* shutdown spooling */
spool_shutdown_context(&answer_list, spooling_context);
answer_list_output(&answer_list);
sge_free(&t);
DEXIT;
return EXIT_SUCCESS;
}