Commit 7ff26906 authored by Kirill Terekhov's avatar Kirill Terekhov

Some updates

parent 501ee30f
......@@ -88,6 +88,7 @@ namespace INMOST
{
Sparse::Matrix jacobian;
Sparse::Vector residual;
Sparse::LockService locks;
public:
Residual(std::string name = "", INMOST_DATA_ENUM_TYPE start = 0, INMOST_DATA_ENUM_TYPE end = 0, INMOST_MPI_Comm _comm = INMOST_MPI_COMM_WORLD)
: jacobian(name,start,end,_comm),residual(name,start,end,_comm) {}
......@@ -175,6 +176,10 @@ namespace INMOST
}
}
}
void InitLocks() {locks.SetInterval(GetFirstIndex(),GetLastIndex());}
void Lock(INMOST_DATA_ENUM_TYPE pos) {if(!locks.Empty()) locks.Lock(pos);}
void UnLock(INMOST_DATA_ENUM_TYPE pos) {if(!locks.Empty()) locks.UnLock(pos);}
void TestLock(INMOST_DATA_ENUM_TYPE pos) {if(!locks.Empty()) locks.TestLock(pos);}
};
class Automatizator
......
......@@ -79,6 +79,7 @@ namespace INMOST
value = other.value;
return *this;
}
operator INMOST_DATA_REAL_TYPE () {return value;}
};
......
......@@ -2351,15 +2351,19 @@ namespace INMOST
void SetParallelFileStrategy(int strategy){assert( !(strategy < 0 || strategy > 1) ); parallel_file_strategy = strategy;}
/// Retrieve currently set parallel strategy for ".pmf" files
/// @see Mesh::GetParallelStrategy
int GetParallelFileStrategy() {return parallel_file_strategy;}
int GetParallelFileStrategy() const {return parallel_file_strategy;}
/// Get rank of current processor
int GetProcessorRank ();
int GetProcessorRank () const;
/// Get number of processors
int GetProcessorsNumber();
int GetProcessorsNumber() const;
/// Get rank of current processor in shared environment (OpenMP)
int GetLocalProcessorRank() const;
/// Get number of processors in shared environment (OpenMP)
int GetLocalProcessorNumber() const;
/// Retrieve MPI communicator
INMOST_MPI_Comm GetCommunicator ();
INMOST_MPI_Comm GetCommunicator () const;
/// Retrieve MPI group corresponding to the communicator
INMOST_MPI_Group GetGroup ();
INMOST_MPI_Group GetGroup () const;
/// Set MPI communicator
void SetCommunicator (INMOST_MPI_Comm _comm);
void ResolveShared ();
......
......@@ -175,9 +175,9 @@ namespace INMOST
/// that allow for the modification of individual entries.
/// @param size New size of the row.
void Resize(INMOST_DATA_ENUM_TYPE size) {data.resize(size);}
void Print()
void Print() const
{
for(iterator it = Begin(); it != End(); ++it) std::cout << "(" << it->first << "," << it->second << ") ";
for(const_iterator it = Begin(); it != End(); ++it) std::cout << "(" << it->first << "," << it->second << ") ";
std::cout << std::endl;
}
bool isSorted() const;
......
......@@ -146,51 +146,67 @@ namespace INMOST
void ParseReference(std::string word, std::vector<std::pair<INMOST::ElementType,int> > & Vector, int & Repeat, int SetSize);
void ParseRemoteReference(std::string word, std::vector< std::pair<std::string,std::pair<INMOST::ElementType,int> > > & Vector, int & Repeat, int SetSize);
/// Structure for xml attribute.
struct XMLAttrib
{
std::string name;
std::string value;
std::string name; //< Name of the attribute.
std::string value; //< Value of the attribute.
};
/// Structure for xml tag with attributes.
struct XMLTag
{
std::string name; //<Name of the XML tag
std::vector<XMLAttrib> attributes; //<List of attributes
int finish; //<Whether to close the tag
std::string name; //<Name of the XML tag.
std::vector<XMLAttrib> attributes; //<List of attributes.
int finish; //<Whether to close the ta.g
///This is data without ![CDATA[ wrap
///This is data without ![CDATA[ wrap.
bool RawData() const {return finish == 5;}
///This is data within ![CDATA[ wrap
///This is data within ![CDATA[ wrap.
bool BlockData() const {return finish == 4;}
///Was not able to read the tag
///Was not able to read the tag.
bool Failure() const {return finish == 0;}
///Tag was red and have internal contents, can process the contents
///Tag was red and have internal contents, can process the contents.
bool Process() const {return finish == 1;}
///Tag was red but do not have internal contents
///Tag was red but do not have internal contents.
bool Stub() const {return finish == 2;}
///Tag was not red, finish of enclosing tag was encountered
///Tag was not red, finish of enclosing tag was encountered.
bool Finalize() const {return finish == 3;}
///Retrive attribute number n.
const XMLAttrib & GetAttib(int n) const {return attributes[n];}
///Retrive attribute number n.
XMLAttrib & GetAttib(int n) {return attributes[n];}
///Retrive number of attributes.
int NumAttrib() const {return (int)attributes.size();}
///Retrive the name of the tag.
std::string GetName() const {return name;}
};
XMLTag OpenTag();
bool CloseTag(XMLTag & tag);
/// Structure defining entire XML file.
struct XMLTree
{
XMLTag tag;
std::vector<XMLTree> children;
std::string contents;
XMLTag tag; //< tag information, such as name and attributes.
std::vector<XMLTree> children; //< Children inside XML tag.
std::string contents; //< Text inside of the tag.
///Return next occurance of XML tag with the specified
///name. Returns NumChildren() if not found.
int FindChild(std::string name, int offset = -1) const;
///Retrive a child of current XML tag with number n.
const XMLTree & GetChild(int n) const {return children[n];}
///Retrive number of children.
int NumChildren() const {return (int)children.size();}
///Retrive attribute of current XML tag with number n.
const XMLAttrib & GetAttrib(int n) const {return tag.GetAttib(n);}
///Retrive number of attributes.
int NumAttrib() const {return (int)tag.NumAttrib();}
///Retrive the name of the tag.
std::string GetName() const {return tag.GetName();}
///Retrive contents of the tag.
const std::string & GetContents() const {return contents;}
};
......@@ -200,12 +216,12 @@ private:
int ReadXMLSub(XMLTree & root);
public:
/// Read entire XML file into structure,
/// it may be more efficient to read the file partially
/// it may be more efficient to read the file incrementially, depending on the size.
/// See mesh_xml_file.cpp for incremential read.
XMLTree ReadXML();
void WriteXML(const XMLTree & t, std::ostream & output, int offset = 0);
};
void WriteXML(const XMLReader::XMLTree & t, std::ostream & output, int offset = 0);
}
......
......@@ -163,10 +163,7 @@ namespace INMOST
{
assert(isPrivate(n));
n &= ~MarkerPrivateBit;
int thread = 0;
#if defined(USE_OMP)
thread = omp_get_thread_num();
#endif
int thread = GetLocalProcessorRank();
const bulk * mem = static_cast<const bulk *>(MGetDenseLink(h,tag_private_markers[thread]));
return (mem[n >> MarkerShift] & static_cast<bulk>(n & MarkerMask)) != 0;
}
......@@ -175,10 +172,7 @@ namespace INMOST
{
assert(isPrivate(n));
n &= ~MarkerPrivateBit;
int thread = 0;
#if defined(USE_OMP)
thread = omp_get_thread_num();
#endif
int thread = GetLocalProcessorRank();
bulk * mem = static_cast<bulk *>(MGetDenseLink(h,tag_private_markers[thread]));
mem[n >> MarkerShift] |= static_cast<bulk>(n & MarkerMask);
}
......@@ -187,10 +181,7 @@ namespace INMOST
{
assert(isPrivate(n));
n &= ~MarkerPrivateBit;
int thread = 0;
#if defined(USE_OMP)
thread = omp_get_thread_num();
#endif
int thread = GetLocalProcessorRank();
bulk * mem = static_cast<bulk *>(MGetDenseLink(h,tag_private_markers[thread]));
mem[n >> MarkerShift] &= ~static_cast<bulk>(n & MarkerMask);
}
......@@ -202,13 +193,13 @@ namespace INMOST
{
#pragma omp single
{
tag_private_markers = new Tag[omp_get_num_threads()];
tag_private_markers = new Tag[GetLocalProcessorNumber()];
}
//#pragma omp ordered
{
std::stringstream name;
name << "PROTECTED_PRIVATE_MARKERS_" << omp_get_thread_num();
tag_private_markers[omp_get_thread_num()] = CreateTag(name.str(),DATA_BULK,CELL|FACE|EDGE|NODE|ESET|MESH,NONE,MarkerFieldsPrivate);
name << "PROTECTED_PRIVATE_MARKERS_" << GetLocalProcessorRank();
tag_private_markers[GetLocalProcessorRank()] = CreateTag(name.str(),DATA_BULK,CELL|FACE|EDGE|NODE|ESET|MESH,NONE,MarkerFieldsPrivate);
}
}
#else
......@@ -217,22 +208,40 @@ namespace INMOST
#endif
}
int Mesh::GetLocalProcessorNumber() const
{
#if defined(USE_OMP)
return omp_get_num_threads();
#else
return 1;
#endif
}
int Mesh::GetLocalProcessorRank() const
{
#if defined(USE_OMP)
return omp_get_thread_num();
#else
return 0;
#endif
}
void Mesh::DeallocatePrivateMarkers()
{
#if defined(USE_OMP)
#pragma omp parallel
{
//retrive tag before it was erased
Tag del = tag_private_markers[omp_get_thread_num()];
//retrive tag before it was erased
Tag del = tag_private_markers[GetLocalProcessorRank()];
#pragma omp barrier
//delete tag, it will erase the tag
DeleteTag(del);
//delete tag, it will erase the tag
DeleteTag(del);
#pragma omp barrier
//deallocate space
//deallocate space
#pragma omp single
{
delete [] tag_private_markers;
}
{
delete [] tag_private_markers;
}
}
#else
DeleteTag(tag_private_markers[0]);
......@@ -1805,12 +1814,9 @@ namespace INMOST
assert(false); //if you reached here then you either don't release markers (it's your bug) or you should increase MarkerFields const in inmost_mesh.h
return InvalidMarker();
}
MarkerType Mesh::CreatePrivateMarker()
{
int thread = 0;
#if defined(USE_OMP)
thread = omp_get_thread_num();
#endif
MarkerType Mesh::CreatePrivateMarker()
{
int thread = GetLocalProcessorRank();
Storage::bulk * marker_space = static_cast<Storage::bulk * >(MGetDenseLink(GetHandle(),tag_private_markers[thread]));
INMOST_DATA_ENUM_TYPE ret;
for(INMOST_DATA_ENUM_TYPE k = 0; k < MarkerFields; ++k)
......@@ -1820,7 +1826,7 @@ namespace INMOST
{
ret = (k << MarkerShift) | mask;
marker_space[k] |= mask;
ret |= MarkerPrivateBit;
ret |= MarkerPrivateBit;
return ret;
}
}
......@@ -1845,15 +1851,12 @@ namespace INMOST
Storage::RemMarker(n);
}
void Mesh::ReleasePrivateMarker(MarkerType n)
void Mesh::ReleasePrivateMarker(MarkerType n)
{
assert(isPrivate(n));
assert(isPrivate(n));
#if defined(CHECKS_MARKERS)
#ifndef NDEBUG
int thread = 0;
#if defined(USE_OMP)
thread = omp_get_thread_num();
#endif
int thread = GetLocalProcessorRank();
for(int etypenum = 0; etypenum < ElementNum(MESH); ++etypenum)
{
integer end = LastLocalIDNum(etypenum);
......
......@@ -516,7 +516,7 @@ namespace INMOST
}
INMOST_MPI_Comm Mesh::GetCommunicator()
INMOST_MPI_Comm Mesh::GetCommunicator() const
{
#if defined(USE_MPI)
return comm;
......@@ -525,7 +525,7 @@ namespace INMOST
#endif //USE_MPI
}
int Mesh::GetProcessorRank()
int Mesh::GetProcessorRank() const
{
#if defined(USE_MPI)
int rank;
......@@ -536,7 +536,7 @@ namespace INMOST
#endif //USE_MPI
}
int Mesh::GetProcessorsNumber()
int Mesh::GetProcessorsNumber() const
{
#if defined(USE_MPI)
int size;
......@@ -571,7 +571,7 @@ namespace INMOST
#endif //USE_MPI
}
INMOST_MPI_Group Mesh::GetGroup()
INMOST_MPI_Group Mesh::GetGroup() const
{
INMOST_MPI_Group ret = INMOST_MPI_GROUP_EMPTY;
#if defined(USE_MPI)
......
......@@ -1594,14 +1594,23 @@ namespace INMOST
while(num > 0) {output.put('\t'); --num;}
return output;
}
int XMLReader::XMLTree::FindChild(std::string name, int offset) const
{
for(int k = offset+1; k < NumChildren(); ++k)
if( GetChild(k).GetName() == name )
return k;
return NumChildren();
}
void XMLReader::WriteXML(const XMLTree & t, std::ostream & output, int offset)
void WriteXML(const XMLReader::XMLTree & t, std::ostream & output, int offset)
{
Tabs(output,offset) << "<" << t.GetName();
for(int k = 0; k < t.NumAttrib(); ++k)
{
const XMLAttrib & attr = t.GetAttrib(k);
const XMLReader::XMLAttrib & attr = t.GetAttrib(k);
output << std::endl;;
Tabs(output,offset+1) << attr.name << "=\"" << attr.value << "\"";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment