#include <fiber/bundle/Bundle.hpp>
#include <fiber/finit/FinitAPI.h>
#include <fiber/field/ArrayRef.hpp>
#include <fiber/field/UniformCartesianArray.hpp>
#include <memcore/MemUsage.hpp>
#undef Verbose
#define Verbose(X) AppVerbose("RUN",X)
static constexpr int
FRAGMENTS_PER_FILE = 6;
static constexpr bool
CREATE_INPUT_FILE = true,
CHECK_FILE_SAVE = false,
CHECK_FILE_COPY_BY_CREATOR_COPY = true,
CHECK_FILE_COPY_BY_DATA_COPY = false;
static constexpr int kB = 1024, MB = kB*kB;
static constexpr memsize_t MEMCORE_CACHESIZE = 8*MB;
void check_file_save()
{
puts("##################### COPY FILE ######################");fflush(stdout);
{
BP.load("InputFile.f5");
BP->iterate_timeslices(
true, [&](
double t,
const Slice&S)
{
Verbose(0) << " T=" << t;
{
Verbose(0) <<
" Grid " << GId.
Name();
{
Verbose(0) <<
" Field " << theFieldID.
Name();
if (CAB)
{
PositionsTracer = Pos;
Verbose(0) << "* File Creator created: *** RAM: "
<< " Cache: "
<< double(theGlobalCache->totalCost())/MB << "MB";
}
return true;
} );
return true;
} );
return true;
}
);
<< "MB Cache: " << double(theGlobalCache->totalCost())/MB << "MB"
<< " -- file has been COMPLETELY loaded at this time, thus full available RAM is used here by now -- "
<< " - if file is larger than RAM, then some data have been forgotten again, and will be required to be loaded again when saving the Output file. - "
;
BP->
save(
"SavedInputFile.f5");
<< "MB Cache: " << double(theGlobalCache->totalCost())/MB << "MB";
}
}
void check_file_copy_by_creator_copy()
{
puts("##################### COPY FILE VIA CREATOR COPY ######################");fflush(stdout);
{
inBP.load("InputFile.f5");
(*outBP).bindToNew("InputFileBoundCopy.f5");
inBP->iterate_timeslices(
true, [&](
double t,
const Slice&S)
{
Verbose(0) << " T=" << t;
{
Verbose(0) <<
" Grid " << GId.
Name();
const RefPtr<CreativeArrayBase>&CAB, const RefPtr<FragmentID>&fid)
{
outBP[t]["Newly Created Grid"].makeCartesianRepresentation(3);
RefPtr<Field>&OutField = myCartesianRepresentation[ theFieldID.
Name() ];
<< "* File Creator created: *** RAM: "
;
return true;
} );
return true;
} );
return true;
}
);
<< " -- NO file data have been loaded at this time already, thus NO RAM has been used here by now -- "
;
}
}
void check_file_copy_by_data_copy()
{
puts("##################### COPY FILE VIA DATA COPY ######################");fflush(stdout);
{
inBP.load("InputFile.f5");
(*outBP).bindToNew("InputFileViaDataCopy.f5");
inBP->iterate_timeslices(
true, [&](
double t,
const Slice&S)
{
Verbose(0) << " T=" << t;
{
Verbose(0) <<
" Grid " << GId.
Name();
const RefPtr<CreativeArrayBase>&CAB, const RefPtr<FragmentID>&fid)
{
outBP[t]["Data Copied Grid"].makeCartesianRepresentation(3);
RefPtr<Field>&OutField = myCartesianRepresentation[ theFieldID.
Name() ];
#if 0
OutField->setPersistentDataByName( CAB->create()->copy(),
FragmentID::Name(fid ));
#else
#endif
<< " Persistent Creator created: *** RAM: "
;
return true;
} );
return true;
} );
return true;
}
);
<< " -- file has been PARTIALLY loaded at this time, thus some RAM is used here by now -- "
<< " - if file is larger than RAM, then some data have already been saved to the new file and forgotten by now; they do not need to be loaded again for saving. - "
;
}
}
{
Finit();
theGlobalCache->setMaxCost( MEMCORE_CACHESIZE );
<< "MB Cache: " << double(theGlobalCache->totalCost())/MB << "MB";
if (CREATE_INPUT_FILE)
{
Representation&myCartesianRepresentation = BP[1.0][
"DemoGrid"].makeCartesianRepresentation(3);
BP->bindToNew("InputFile.f5");
RefPtr<Field>&Positions = myCartesianRepresentation[ FIBER_POSITIONS ];
for(int i=0; i<FRAGMENTS_PER_FILE; i++)
{
for(auto I : GridDims)
{
point&P = Coordinates[ I ];
P.x() = I[0]*0.1;
P.y() = I[1]*0.2;
P.z() = I[2]*0.3;
}
if (MemBase::Creator_t
CoordinateCreator = Positions->createCreator(Coordinates,
"Some Test Fragment " +
std:: to_string(i) ) )
{
CoordinateCreator->touch();
}
}
Verbose(0) <<
"**** RAM: " << double(
getMemUsage() - InitialRAM )/MB
<< " Cache: " << double(theGlobalCache->totalCost())/MB << "MB";
}
Verbose(0) <<
"*** Input File created, closed, cleaned up -RAM: " << double(
getMemUsage() - InitialRAM )/MB
<< " Cache: " << double(theGlobalCache->totalCost())/MB << "MB";
Assert( theGlobalCache->totalCost() == 0);
if (CHECK_FILE_SAVE)
check_file_save();
if (CHECK_FILE_COPY_BY_CREATOR_COPY)
check_file_copy_by_creator_copy();
if (CHECK_FILE_COPY_BY_DATA_COPY)
check_file_copy_by_data_copy();
return 0;
}
int main()
Demonstrates minimal usage of the FiberLib Create Bundle, insert a time slice, and safe it to a file.
Definition 010-SimpleSave.cpp:13
An array reference class, which is a convenience class for reference pointers to multidimensional mem...
Definition ArrayRef.hpp:28
Convenience class that implements a pointer to a Bundle object but adds some useful member funtions t...
Definition Bundle.hpp:779
int save(const string &url, const RefPtr< LoaderProgress > &SaveProgress=nullptr, const RefPtrStorageTransformations &ST=nullptr)
Definition Bundle.cpp:1142
Identifier for Fields within a Grid.
Definition FieldID.hpp:53
const string & Name() const
Get the textual description.
Definition FieldID.hpp:86
A Field is a collection of CreativeArrayBase reference pointers which are accessed via FragmentID obj...
Definition Field.hpp:245
const string & Name() const
Text ID of the fragment.
Definition FragmentID.hpp:65
A grid identifier.
Definition GridID.hpp:29
const string & Name() const
Get the name associated with this Grid ID.
Definition GridID.hpp:131
A Grid is a set of Skeleton objects, each of them accessed via some unique SkeletonID object.
Definition Grid.hpp:60
int iterate_all(const Functor &F) const
Lambda functor iteration over all data.
Definition SkeletonMap.hpp:260
A multidimensional index that is automatically a lower-dimensional index via recursion.
Definition MultiIndex.hpp:449
A Representation is a set of Field objects, each of them accessed via some FieldID identifier.
Definition Representation.hpp:101
A Skeleton is a set of Representation object, each of them accessed by an Representer object.
Definition Skeleton.hpp:102
Information per time slice, mainly a set of Grid objects that are accessed via GridID objects.
Definition Slice.hpp:36
int iterate_grids(const Functor &F) const
Lambda iterator for bundles, provides Slices: @eode iterate_grids( [](const GridID&GId,...
Definition Slice.hpp:197
static RefPtr< Cache, CacheBase > & MemCache()
MemSizeConfig< sizeof(void *)>::memsize_t memsize_t
StrongPtr< Object, ObjectBase > RefPtr
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
WeakPtr< BaseSpace > Representer
The type used to reference other objects, which is the anchor of representations of a Skeleton.
Definition RepresentationMap.hpp:28
unsigned long long getMemUsage()
double getRelativeMemUsageMiB()
unsigned long long setInitialMemUsage()
string to_string(const Eagle::FixedArray< ElementType, N > &A, const char *OpenBrace="{", const char *CloseBrace="}", const char *Separator=",")