59 entryOnMultipleProcs_(false),
63 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
66 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
86 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 96 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 106 throw "Epetra_BasicDirectory::Epetra_BasicDirectory: Unknown map index type";
114 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
115 flag = Generate<int>(Map);
117 throw "Epetra_BasicDirectory::Epetra_BasicDirectory: ERROR, GlobalIndicesInt but no API for it.";
120 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
121 flag = Generate<long long>(Map);
123 throw "Epetra_BasicDirectory::Epetra_BasicDirectory: ERROR, GlobalIndicesLongLong but no API for it.";
138 entryOnMultipleProcs_(false),
141 SizeIsConst_(Directory.SizeIsConst_)
142 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
145 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
165 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 172 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 186 for(
int i=0; i<num; ++i) {
193 for(
int j=0; j<len; ++j) {
221 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 225 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 252 int insertPoint = -1;
264 template<
typename int_type>
273 int_type Dir_NumGlobalElements = MaxAllGID - MinAllGID + 1;
284 if (Dir_NumMyElements>0) {
285 ProcList_ =
new int[ Dir_NumMyElements ];
291 for (i=0; i<Dir_NumMyElements; i++) {
304 int * send_procs = 0;
305 if (Map_NumMyElements>0) send_procs =
new int[Map_NumMyElements];
306 int_type * Map_MyGlobalElements = 0;
307 #if !defined(EPETRA_NO_32BIT_GLOBAL_INDICES) || !defined(EPETRA_NO_64BIT_GLOBAL_INDICES) 311 Map_MyGlobalElements,
315 bool det_flag =
true;
323 if (Map_NumMyElements>0)
delete [] send_procs;
325 int * export_elements = 0;
326 char * c_import_elements = 0;
327 int * import_elements = 0;
328 int len_import_elements = 0;
329 int * ElementSizeList = 0;
331 int packetSize = (int) (
sizeof(int_type) + 2*
sizeof(int))/
sizeof(int);
334 if (Map_NumMyElements>0) {
336 export_elements =
new int[ packetSize * Map_NumMyElements ];
337 int * ptr = export_elements;
338 for( i = 0; i < Map_NumMyElements; i++ )
340 *(int_type*)ptr = Map_MyGlobalElements[i];
341 ptr +=
sizeof(int_type)/
sizeof(
int);
352 packetSize * (
int)
sizeof(
int ),
354 c_import_elements ));
356 import_elements =
reinterpret_cast<int *
>(c_import_elements);
361 int * ptr = import_elements;
362 for( i = 0; i < num_recvs; i++ )
365 ptr +=
sizeof(int_type)/
sizeof(
int);
367 assert(curr_LID !=-1);
389 int localval, globalval;
394 if (len_import_elements!=0)
delete [] c_import_elements;
395 if (export_elements!=0)
delete [] export_elements;
411 template<
typename int_type>
413 const int NumEntries,
414 const int_type * GlobalEntries,
418 bool high_rank_sharing_procs)
const 433 int * ElementSizeList = 0;
435 if (ConstantElementSize)
439 for (i=0; i<NumEntries; i++) {
440 int LID = Map.
LID(GlobalEntries[i]);
446 else Procs[i] = MyPID;
449 if (LocalEntries!=0) LocalEntries[i] = LID;
453 if (ConstantElementSize)
454 EntrySizes[i] = ElementSize;
456 EntrySizes[i] = ElementSizeList[LID];
470 for (i=0; i<NumEntries; i++) {
473 int_type GID = GlobalEntries[i];
474 if (GID<MinAllGID) ierr = 1;
475 else if (GID>MaxAllGID) ierr = 1;
480 const int_type* AllMinGIDs_ptr = AllMinGIDs<int_type>();
482 while (Proc1 >= 0 && Proc1< NumProc) {
483 if (AllMinGIDs_ptr[Proc1]<=GID) {
484 if (GID <AllMinGIDs_ptr[Proc1+1]) {
494 LID = (int) (GID - AllMinGIDs_ptr[Proc]);
498 if (LocalEntries!=0) LocalEntries[i] = LID;
503 for (i=0; i<NumEntries; i++) EntrySizes[i] = ElementSize;
512 int_type * Size_send_gids = 0;
513 int * Size_send_procs = 0;
517 Size_num_sends, Size_send_gids, Size_send_procs ));
519 int * Size_exports = 0;
520 char * c_Size_imports = 0;
521 int * Size_imports = 0;
522 int packetSize = (int) (
sizeof(int_type) +
sizeof(int))/
sizeof(int);
523 if (Size_num_sends>0) {
524 Size_exports =
new int[ packetSize * Size_num_sends ];
525 for( i = 0; i < Size_num_sends; i++ )
527 int_type Size_curr_GID = Size_send_gids[i];
528 int Size_curr_LID = Map.
LID(Size_curr_GID);
529 assert(Size_curr_LID!=-1);
530 *(int_type*)(Size_exports + packetSize*i) = Size_curr_GID;
531 int Size_curr_size = ElementSizeList[Size_curr_LID];
532 *(Size_exports + packetSize*i + (packetSize - 1)) = Size_curr_size;
536 int len_Size_imports = 0;
538 packetSize * (
int)
sizeof(
int ),
541 Size_imports =
reinterpret_cast<int*
>(c_Size_imports);
543 for( i = 0; i < NumEntries; i++ )
548 int_type Size_curr_GID = *(int_type*)(Size_imports + packetSize*i);
549 for( j = 0; j < NumEntries; j++ )
550 if( Size_curr_GID == GlobalEntries[j] )
552 EntrySizes[j] = *(Size_imports + packetSize*i + (packetSize - 1));
560 if( Size_send_gids != 0 )
delete [] Size_send_gids;
561 if( Size_send_procs != 0 )
delete [] Size_send_procs;
563 if( len_Size_imports != 0 )
delete [] c_Size_imports;
564 if( Size_exports != 0 )
delete [] Size_exports;
575 int PacketSize = (int) (
sizeof(int_type) +
sizeof(int))/
sizeof(int);
576 bool DoSizes =
false;
580 for (i=0; i<NumEntries; i++) EntrySizes[i] = ElementSize;
588 bool DoLIDs = (LocalEntries!=0);
589 if (DoLIDs) PacketSize++;
596 if (NumEntries>0) dir_procs =
new int[ NumEntries ];
598 #if !defined(EPETRA_NO_32BIT_GLOBAL_INDICES) || !defined(EPETRA_NO_64BIT_GLOBAL_INDICES) 605 {
for( i = 0; i < NumEntries; ++i )
606 if( dir_procs[i] == -1 )
609 if (DoLIDs) LocalEntries[i] = -1;
614 int_type * send_gids = 0;
615 int * send_procs = 0;
618 num_sends, send_gids, send_procs));
620 if (NumEntries>0)
delete [] dir_procs;
625 char * c_imports = 0;
629 exports =
new int[ PacketSize * num_sends ];
631 for( i = 0; i < num_sends; i++ )
633 int_type curr_GID = send_gids[i];
634 *(int_type*)ptr = curr_GID;
635 ptr +=
sizeof(int_type)/
sizeof(
int);
637 assert(curr_LID!=-1);
638 if (high_rank_sharing_procs==
false) {
660 if (DoSizes) *ptr++ =
SizeList_[curr_LID];
664 int NumRecv = NumEntries - NumMissing;
666 PacketSize * (
int)
sizeof(
int ),
669 imports =
reinterpret_cast<int*
>(c_imports);
674 int* sortedGE_int =
new int[NumEntries*(1 +
sizeof(int_type)/
sizeof(
int))];
675 int* offsets = sortedGE_int+NumEntries*
sizeof(int_type)/
sizeof(
int);
676 int_type* sortedGE =
reinterpret_cast<int_type*
>(sortedGE_int);
678 for(i=0; i<NumEntries; ++i) {
682 std::memcpy(sortedGE, GlobalEntries, NumEntries*
sizeof(int_type));
684 Utils.
Sort(
true, NumEntries, sortedGE, 0, 0, 1, &offsets, 0, 0);
689 for( i = 0; i < NumRecv; i++ ) {
690 int_type theCurrentLID = *(int_type*)ptr;
691 ptr +=
sizeof(int_type)/
sizeof(
int);
694 Procs[offsets[j]] = *ptr++;
695 if (DoLIDs) LocalEntries[offsets[j]] = *ptr++;
696 if (DoSizes) EntrySizes[offsets[j]] = *ptr++;
700 delete [] sortedGE_int;
702 if( send_gids )
delete [] send_gids;
703 if( send_procs )
delete [] send_procs;
705 if( len_imports )
delete [] c_imports;
706 if( exports )
delete [] exports;
713 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 715 const int NumEntries,
716 const int * GlobalEntries,
720 bool high_rank_sharing_procs)
const 723 throw "Epetra_BasicDirectory::GetDirectoryEntries: int version can't be called for non int map";
725 return GetDirectoryEntries<int>(Map, NumEntries, GlobalEntries, Procs,
726 LocalEntries, EntrySizes, high_rank_sharing_procs);
730 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 735 const int NumEntries,
736 const long long * GlobalEntries,
740 bool high_rank_sharing_procs)
const 743 throw "Epetra_BasicDirectory::GetDirectoryEntries: long long version can't be called for non long long map";
745 return GetDirectoryEntries<long long>(Map, NumEntries, GlobalEntries, Procs,
746 LocalEntries, EntrySizes, high_rank_sharing_procs);
756 os << MyPID <<
" Epetra_BasicDirectory Object: " 759 os <<
" " << i <<
" " <<
ProcList_[i] <<
" " 769 std::cout <<
"Epetra_BasicDirectory not setup<<<<<<" << std::endl;
780 bool throw_error =
true;
782 std::cerr << std::endl
783 <<
"Epetra_BasicDirectory::operator= not supported."
Epetra_Map: A class for partitioning vectors and matrices.
bool entryOnMultipleProcs_
long long MinMyGID64() const
Epetra_Distributor: The Epetra Gather/Scatter Setup Base Class.
bool DistributedGlobal() const
Returns true if map is defined across more than one processor.
bool ConstantElementSize() const
Returns true if map has constant element size.
virtual int GatherAll(double *MyVals, double *AllVals, int Count) const =0
Epetra_Comm All Gather function.
Epetra_BasicDirectory(const Epetra_BlockMap &Map)
Epetra_BasicDirectory constructor.
virtual int CreateFromSends(const int &NumExportIDs, const int *ExportPIDs, bool Deterministic, int &NumRemoteIDs)=0
Create Distributor object using list of process IDs to which we export.
virtual ~Epetra_BasicDirectory(void)
Epetra_BasicDirectory destructor.
#define EPETRA_CHK_ERR(a)
long long NumGlobalElements64() const
const Epetra_Map & DirectoryMap() const
Returns the Epetra_Map containing the directory.
int GetDirectoryEntries(const Epetra_BlockMap &Map, const int NumEntries, const int *GlobalEntries, int *Procs, int *LocalEntries, int *EntrySizes, bool high_rank_sharing_procs=false) const
GetDirectoryEntries : Returns proc and local id info for non-local map entries.
virtual int MyPID() const =0
Return my process ID.
int * ElementSizeList() const
List of the element sizes corresponding to the array MyGlobalElements().
virtual int MaxAll(double *PartialMaxs, double *GlobalMaxs, int Count) const =0
Epetra_Comm Global Max function.
long long MaxAllGID64() const
Epetra_Util: The Epetra Util Wrapper Class.
int Generate(const Epetra_BlockMap &Map)
Generate: Sets up Directory tables.
void create_ProcListArrays()
Epetra_BasicDirectory: This class allows Epetra_Map objects to reference non-local elements...
bool GIDsAllUniquelyOwned() const
GIDsAllUniquelyOwned: returns true if all GIDs appear on just one processor.
bool GlobalIndicesInt() const
Returns true if map create with int NumGlobalElements.
int NumMyElements() const
Number of elements on the calling processor.
Epetra_BlockMap: A class for partitioning block element vectors and matrices.
const Epetra_Comm & Comm() const
Access function for Epetra_Comm communicator.
long long * AllMinGIDs_LL_
int RemoteIDList(int NumIDs, const int *GIDList, int *PIDList, int *LIDList) const
Returns the processor IDs and corresponding local index value for a given list of global indices...
int Epetra_Util_binary_search(T item, const T *list, int len, int &insertPoint)
Utility function to perform a binary-search on a list of data.
Epetra_BasicDirectory & operator=(const Epetra_BasicDirectory &src)
virtual int Do(char *export_objs, int obj_size, int &len_import_objs, char *&import_objs)=0
Execute plan on buffer of export objects in a single step.
int LID(int GID) const
Returns local ID of global ID, return -1 if not found on this processor.
long long MinAllGID64() const
virtual int CreateFromRecvs(const int &NumRemoteIDs, const int *RemoteGIDs, const int *RemotePIDs, bool Deterministic, int &NumExportIDs, int *&ExportGIDs, int *&ExportPIDs)=0
Create Distributor object using list of Remote global IDs and corresponding PIDs. ...
virtual int NumProc() const =0
Returns total number of processes.
Epetra_Map * DirectoryMap_
virtual Epetra_Distributor * CreateDistributor() const =0
Create a distributor object.
int MaxElementSize() const
Maximum element size across all processors.
void addProcToList(int proc, int LID)
static void Sort(bool SortAscending, int NumKeys, T *Keys, int NumDoubleCompanions, double **DoubleCompanions, int NumIntCompanions, int **IntCompanions, int NumLongLongCompanions, long long **LongLongCompanions)
Epetra_Util Sort Routine (Shell sort)
int MyGlobalElementsPtr(int *&MyGlobalElementList) const
bool LinearMap() const
Returns true if the global ID space is contiguously divided (but not necessarily uniformly) across al...
virtual void Print(std::ostream &os) const
Print method.
bool GlobalIndicesLongLong() const
Returns true if map create with long long NumGlobalElements.
int Epetra_Util_insert(T item, int offset, T *&list, int &usedLength, int &allocatedLength, int allocChunkSize=32)
Function to insert an item in a list, at a specified offset.