本文整理汇总了C++中Obj::allocate方法的典型用法代码示例。如果您正苦于以下问题:C++ Obj::allocate方法的具体用法?C++ Obj::allocate怎么用?C++ Obj::allocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Obj
的用法示例。
在下文中一共展示了Obj::allocate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DMMeshCreateMeshFromAdjacencyHybrid
PetscErrorCode DMMeshCreateMeshFromAdjacencyHybrid(MPI_Comm comm, PetscInt dim, PetscInt numCells, PetscInt numCorners[], PetscInt cellVertices[], PetscInt spatialDim, PetscInt numVertices, const PetscReal coordinates[], PetscBool interpolate, DM *dm) {
PetscInt debug = 0;
PetscErrorCode ierr;
PetscFunctionBegin;
PetscValidPointer(numCorners, 4);
PetscValidPointer(cellVertices, 5);
/* PetscValidLogicalCollectiveBool(comm,interpolate,6); */
PetscValidPointer(dm, 7);
if (interpolate) {SETERRQ(comm, PETSC_ERR_SUP, "Interpolation (creation of faces and edges) is not yet supported.");}
ierr = PetscOptionsGetInt(PETSC_NULL, "-dmmesh_debug", &debug, PETSC_NULL);CHKERRQ(ierr);
Obj<PETSC_MESH_TYPE> mesh = new PETSC_MESH_TYPE(comm, dim, debug);
Obj<PETSC_MESH_TYPE::sieve_type> sieve = new PETSC_MESH_TYPE::sieve_type(comm, 0, numCells+numVertices, debug);
mesh->setSieve(sieve);
for(PetscInt c = 0; c < numCells; ++c) {
sieve->setConeSize(c, numCorners[c]);
}
//sieve->symmetrizeSizes(numCells, numCorners, cellVertices);
sieve->allocate();
for(PetscInt c = 0, offset = 0; c < numCells; offset += numCorners[c], ++c) {
sieve->setCone(&cellVertices[offset], c);
}
sieve->symmetrize();
PetscFunctionReturn(0);
}
示例2: DMMeshCreateMeshFromAdjacency
/*@
DMMeshCreateMeshFromAdjacency - Create an unstrctured mesh from a list of the vertices for each cell, and the coordinates for each vertex.
Collective on comm
Input Parameters:
+ comm - An MPI communicator
. dim - The dimension of the cells, e.g. triangles have dimension 2
. numCells - The number of cells in the mesh
. numCorners - The number of vertices in each cell
. cellVertices - An array of the vertices for each cell, numbered 0 to numVertices-1
. spatialDim - The dimension for coordinates, e.g. for a triangle in 3D this would be 3
. numVertices - The number of mesh vertices
. coordinates - An array of the coordinates for each vertex
- interpolate - Flag to create faces and edges
Output Parameter:
. dm - The DMMesh object
Level: beginner
.seealso DMMESH, DMMeshCreateMeshFromAdjacencyHybrid(), DMMeshCreateBoxMesh()
@*/
PetscErrorCode DMMeshCreateMeshFromAdjacency(MPI_Comm comm, PetscInt dim, PetscInt numCells, PetscInt numCorners, PetscInt cellVertices[], PetscInt spatialDim, PetscInt numVertices, const PetscReal coordinates[], PetscBool interpolate, DM *dm) {
PetscInt *cone;
PetscInt *coneO;
PetscInt debug = 0;
PetscErrorCode ierr;
PetscFunctionBegin;
PetscValidPointer(cellVertices, 5);
/* PetscValidLogicalCollectiveBool(comm,interpolate,6); */
PetscValidPointer(dm, 7);
if (interpolate) {SETERRQ(comm, PETSC_ERR_SUP, "Interpolation (creation of faces and edges) is not yet supported.");}
ierr = PetscOptionsGetInt(PETSC_NULL, "-dm_mesh_debug", &debug, PETSC_NULL);CHKERRQ(ierr);
Obj<PETSC_MESH_TYPE> mesh = new PETSC_MESH_TYPE(comm, dim, debug);
Obj<PETSC_MESH_TYPE::sieve_type> sieve = new PETSC_MESH_TYPE::sieve_type(comm, 0, numCells+numVertices, debug);
mesh->setSieve(sieve);
for(PetscInt c = 0; c < numCells; ++c) {
sieve->setConeSize(c, numCorners);
}
sieve->symmetrizeSizes(numCells, numCorners, cellVertices, numCells);
sieve->allocate();
ierr = PetscMalloc2(numCorners,PetscInt,&cone,numCorners,PetscInt,&coneO);CHKERRQ(ierr);
for(PetscInt v = 0; v < numCorners; ++v) {
coneO[v] = 1;
}
for(PetscInt c = 0; c < numCells; ++c) {
for(PetscInt v = 0; v < numCorners; ++v) {
cone[v] = cellVertices[c*numCorners+v]+numCells;
}
sieve->setCone(cone, c);
sieve->setConeOrientation(coneO, c);
}
ierr = PetscFree2(cone,coneO);CHKERRQ(ierr);
sieve->symmetrize();
mesh->stratify();
ALE::SieveBuilder<PETSC_MESH_TYPE>::buildCoordinates(mesh, spatialDim, coordinates, numCells);
ierr = DMCreate(comm, dm);CHKERRQ(ierr);
ierr = DMSetType(*dm, DMMESH);CHKERRQ(ierr);
ierr = DMMeshSetMesh(*dm, mesh);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例3: ASSERT
extern "C" void *workerThread(void *arg) {
// Perform a series of allocate, and deallocate operations on the
// 'bdlma::ConcurrentAllocatorAdapter' and verify their results. This
// operation is intended to be a thread entry point. Cast the specified
// 'args' to a 'WorkerArgs', and perform a series of
// '(WorkerArgs *)args->d_numSizes' allocations using the corresponding
// allocations sizes specified by '(WorkerARgs *)args->d_sizes'. Use the
// barrier 'g_barrier' to ensure tests are performed while the allocator is
// in the correct state.
WorkerArgs *args = (WorkerArgs *) arg;
ASSERT(0 != args);
ASSERT(0 != args->d_sizes);
Obj *allocator = args->d_allocator;
const int *allocSizes = args->d_sizes;
const int numAllocs = args->d_numSizes;
bsl::vector<char *> blocks(bslma::Default::allocator(0));
blocks.resize(numAllocs);
g_barrier.wait();
// Perform allocations
for (int i = 0; i < numAllocs; ++i) {
blocks[i] = (char *)allocator->allocate(allocSizes[i]);
}
// deallocate all the blocks
for (int i = 0; i < numAllocs; ++i) {
allocator->deallocate(blocks[i]);
}
g_barrier.wait();
return arg;
}
示例4: main
int main(int argc, char *argv[])
{
int test = argc > 1 ? atoi(argv[1]) : 0;
int verbose = argc > 2;
int veryVerbose = argc > 3;
int veryVeryVerbose = argc > 4;
int veryVeryVeryVerbose = argc > 5;
cout << "TEST " << __FILE__ << " CASE " << test << endl;
// CONCERN: In no case does memory come from the global allocator.
bslma::TestAllocator globalAllocator(veryVeryVerbose);
bslma::Default::setGlobalAllocator(&globalAllocator);
switch (test) { case 0:
case 5: {
// --------------------------------------------------------------------
// USAGE EXAMPLE
// Extracted from component header file.
//
// Concerns:
//: 1 The usage example provided in the component header file compiles,
//: links, and runs as shown.
//
// Plan:
//: 1 Incorporate usage example from header into test driver, remove
//: leading comment characters, and replace 'assert' with 'ASSERT'.
//: (C-1)
//
// Testing:
// USAGE EXAMPLE
// --------------------------------------------------------------------
if (verbose) cout << endl
<< "USAGE EXAMPLE" << endl
<< "=============" << endl;
bslma::TestAllocator oa("object", veryVeryVerbose);
if (verbose) cout << "Testing 'my_StrPool'." << endl;
{
const int SIZE[] = { 0, 10, 127, 128, 129, 1000 };
const int NUM_DATA = sizeof SIZE / sizeof *SIZE;
my_StrPool strPool(&oa);
for (int ti = 0; ti < NUM_DATA; ++ti) {
void *p = strPool.allocate(SIZE[ti]);
if (veryVerbose) { T_; P_(SIZE[ti]); P(p); }
if (SIZE[ti]) {
LOOP_ASSERT(ti, p);
} else {
LOOP_ASSERT(ti, !p);
}
}
}
ASSERT(0 == oa.numBlocksInUse());
} break;
case 4: {
// --------------------------------------------------------------------
// TESTING DEALLOCATE
// Ensure that 'deallocate' releases the referenced memory block to
// the object allocator.
//
// Concerns:
//: 1 The memory block at (non-null) 'address' is released to the
//: object allocator.
//:
//: 2 A memory block at any position in the block list can be
//: deallocated.
//:
//: 3 Calling 'deallocate' with a null address has no effect.
//
// Plan:
//: 1 Create a 'bslma::TestAllocator' object, and install it as the
//: default allocator (note that a ubiquitous test allocator is
//: already installed as the global allocator).
//:
//: 2 Using the table-driven technique:
//:
//: 1 Specify a set of unique test pairs consisting of 'N', a
//: positive number of allocations, and 'SEQ', the sequence in
//: which the 'N' allocated blocks are to be deallocated.
//:
//: 3 For each row 'R' (representing a pair '(N, SEQ)') in the table
//: described in P-2: (C-1..2)
//:
//: 1 Create a 'bslma::TestAllocator' object 'oa'.
//:
//: 2 Use the default constructor and 'oa' to create a modifiable
//: 'Obj' 'mX'.
//:
//: 3 Allocate 'N' blocks from 'mX'.
//:
//: 4 Deallocate the 'N' blocks allocated in P-3 in the sequence
//: specified by 'SEQ', and verify that each block is released to
//: the object allocator. (C-1..2)
//:
//.........这里部分代码省略.........