本文整理汇总了C++中OptionParser::getOptionFloat方法的典型用法代码示例。如果您正苦于以下问题:C++ OptionParser::getOptionFloat方法的具体用法?C++ OptionParser::getOptionFloat怎么用?C++ OptionParser::getOptionFloat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OptionParser
的用法示例。
在下文中一共展示了OptionParser::getOptionFloat方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
StencilFactory<T>::ExtractOptions( const OptionParser& options,
T& wCenter,
T& wCardinal,
T& wDiagonal )
{
wCenter = options.getOptionFloat( "weight-center" );
wCardinal = options.getOptionFloat( "weight-cardinal" );
wDiagonal = options.getOptionFloat( "weight-diagonal" );
}
示例2: InvalidArgValue
// validate stencil-independent values
void
CheckOptions( const OptionParser& opts )
{
// check matrix dimensions - must be 2d, must be positive
std::vector<long long> arrayDims = opts.getOptionVecInt( "customSize" );
if( arrayDims.size() != 2 )
{
throw InvalidArgValue( "overall size must have two dimensions" );
}
if( (arrayDims[0] < 0) || (arrayDims[1] < 0) )
{
throw InvalidArgValue( "each size dimension must be positive" );
}
// validation error threshold must be positive
float valThreshold = opts.getOptionFloat( "val-threshold" );
if( valThreshold <= 0.0f )
{
throw InvalidArgValue( "validation threshold must be positive" );
}
// number of validation errors to print must be non-negative
int nErrsToPrint = opts.getOptionInt( "val-print-limit" );
if( nErrsToPrint < 0 )
{
throw InvalidArgValue( "number of validation errors to print must be non-negative" );
}
int nWarmupPasses = opts.getOptionInt( "warmupPasses" );
if( nWarmupPasses < 0 )
{
throw InvalidArgValue( "number of warmup passes must be non-negative" );
}
}
示例3: RunTest
void RunTest(cl_device_id dev, cl_context ctx, cl_command_queue queue,
ResultDatabase &resultDB, OptionParser &op, string compileFlags,
int nRows=0)
{
// Determine if the device is capable of using images in general
cl_device_id device_id;
cl_bool deviceSupportsImages;
int err = 0;
err = clGetCommandQueueInfo(queue, CL_QUEUE_DEVICE, sizeof(device_id),
&device_id, NULL);
CL_CHECK_ERROR(err);
err = clGetDeviceInfo(device_id, CL_DEVICE_IMAGE_SUPPORT,
sizeof(deviceSupportsImages), &deviceSupportsImages, NULL);
CL_CHECK_ERROR(err);
size_t maxImgWidth = 0;
err = clGetDeviceInfo(device_id, CL_DEVICE_IMAGE2D_MAX_WIDTH,
sizeof(size_t), &maxImgWidth, NULL);
CL_CHECK_ERROR(err);
// Make sure our sampler type is supported
cl_sampler sampler;
sampler = clCreateSampler(ctx, CL_FALSE, CL_ADDRESS_NONE,
CL_FILTER_NEAREST, &err);
if (err != CL_SUCCESS)
{
cout << "Warning: Device does not support required sampler type";
cout << " falling back to global memory\n";
deviceSupportsImages = false;
} else
{
clReleaseSampler(sampler);
}
// Host data structures
// array of values in the sparse matrix
floatType *h_val, *h_valPad;
// array of column indices for each value in h_val
int *h_cols, *h_colsPad;
// array of indices to the start of each row in h_val/valPad
int *h_rowDelimiters, *h_rowDelimitersPad;
// Dense vector of values
floatType *h_vec;
// Output vector
floatType *h_out;
// Reference solution computed by cpu
floatType *refOut;
int nItems; // number of non-zero elements in the matrix
int nItemsPadded;
int numRows; // number of rows in the matrix
// This benchmark either reads in a matrix market input file or
// generates a random matrix
string inFileName = op.getOptionString("mm_filename");
if (inFileName == "random")
{
// If we're not opening a file, the dimension of the matrix
// has been passed in as an argument
numRows = nRows;
nItems = numRows * numRows / 100; // 1% of entries will be non-zero
float maxval = op.getOptionFloat("maxval");
h_val = new floatType[nItems];
h_cols = new int[nItems];
h_rowDelimiters = new int[nRows+1];
fill(h_val, nItems, maxval);
initRandomMatrix(h_cols, h_rowDelimiters, nItems, numRows);
}
else
{ char filename[FIELD_LENGTH];
strcpy(filename, inFileName.c_str());
readMatrix(filename, &h_val, &h_cols, &h_rowDelimiters,
&nItems, &numRows);
}
// Final Image Check -- Make sure the image format is supported.
int imgHeight = (numRows+maxImgWidth-1)/maxImgWidth;
cl_image_format fmt;
fmt.image_channel_data_type = CL_FLOAT;
if(sizeof(floatType)==4)
{
fmt.image_channel_order=CL_R;
}
else
{
fmt.image_channel_order=CL_RG;
}
cl_mem d_vec = clCreateImage2D(ctx, CL_MEM_READ_ONLY, &fmt, maxImgWidth,
imgHeight, 0, NULL, &err);
if (err != CL_SUCCESS)
{
deviceSupportsImages = false;
} else {
clReleaseMemObject(d_vec);
}
//.........这里部分代码省略.........
示例4: assert
void
DoTest( const char* timerDesc, ResultDatabase& resultDB, OptionParser& opts )
{
StencilFactory<T>* stdStencilFactory = NULL;
Stencil<T>* stdStencil = NULL;
StencilFactory<T>* testStencilFactory = NULL;
Stencil<T>* testStencil = NULL;
//try
{
stdStencilFactory = new HostStencilFactory<T>;
testStencilFactory = new MICStencilFactory<T>;
assert( (stdStencilFactory != NULL) && (testStencilFactory != NULL) );
// do a sanity check on option values
CheckOptions( opts );
stdStencilFactory->CheckOptions( opts );
testStencilFactory->CheckOptions( opts );
// extract and validate options
std::vector<long long> arrayDims = opts.getOptionVecInt( "customSize" );
if( arrayDims.size() != 2 )
{
cerr << "Dim size: " << arrayDims.size() << "\n";
//throw InvalidArgValue( "all overall dimensions must be positive" );
}
if (arrayDims[0] == 0) // User has not specified a custom size
{
const int probSizes[4] = { 768, 1408, 2048, 4096 };
int sizeClass = opts.getOptionInt("size");
if (!(sizeClass >= 0 && sizeClass < 5))
{
//throw InvalidArgValue( "Size class must be between 1-4" );
}
arrayDims[0] = arrayDims[1] =probSizes[sizeClass - 1];
}
long int seed = (long)opts.getOptionInt( "seed" );
bool beVerbose = opts.getOptionBool( "verbose" );
unsigned int nIters = (unsigned int)opts.getOptionInt( "num-iters" );
double valErrThreshold = (double)opts.getOptionFloat( "val-threshold" );
unsigned int nValErrsToPrint = (unsigned int)opts.getOptionInt( "val-print-limit" );
#if defined(PARALLEL)
unsigned int haloWidth = (unsigned int)opts.getOptionInt( "iters-per-exchange" );
#else
unsigned int haloWidth = 1;
#endif // defined(PARALLEL)
float haloVal = (float)opts.getOptionFloat( "haloVal" );
// build a description of this experiment
std::ostringstream experimentDescriptionStr;
experimentDescriptionStr
<< nIters << ':'
<< arrayDims[0] << 'x' << arrayDims[1] << ':'
<< LROWS << 'x' << LCOLS;
unsigned int nPasses =(unsigned int)opts.getOptionInt( "passes" );
unsigned long npts = (arrayDims[0] + 2*haloWidth - 2) *
(arrayDims[1] + 2*haloWidth - 2);
unsigned long nflops = npts * 11 * nIters;
cout<<"flops are = "<<nflops<<endl;
// compute the expected result on the host
#if defined(PARALLEL)
int cwrank;
MPI_Comm_rank( MPI_COMM_WORLD, &cwrank );
if( cwrank == 0 )
{
#endif // defined(PARALLEL)
std::cout << "\nPerforming stencil operation on host for later comparison with MIC output\n"
<< "Depending on host capabilities, this may take a while."
<< std::endl;
#if defined(PARALLEL)
}
#endif // defined(PARALLEL)
Matrix2D<T> exp( arrayDims[0] + 2*haloWidth,
arrayDims[1] + 2*haloWidth );
Initialize<T> init( seed,
haloWidth,
haloVal );
init( exp );
if( beVerbose )
{
std::cout << "initial state:\n" << exp << std::endl;
}
Stencil<T>* stdStencil = stdStencilFactory->BuildStencil( opts );
(*stdStencil)( exp, nIters );
if( beVerbose )
{
std::cout << "expected result:\n" << exp << std::endl;
}
// compute the result on the MIC device
Matrix2D<T> data( arrayDims[0] + 2*haloWidth,
arrayDims[1] + 2*haloWidth );
//.........这里部分代码省略.........