Actual source code: eindexspace.c
2: /*
3: Makes a PETSc Map look like an esi::IndexSpace
4: */
6: #include esi/petsc/indexspace.h
8: esi::petsc::IndexSpace<int>::IndexSpace(MPI_Comm icomm, int n, int N)
9: {
11: PetscMapCreateMPI(icomm,n,N,&this->map);if (ierr) return;
12: PetscObjectGetComm((PetscObject)this->map,&this->comm);if (ierr) return;
13: }
15: esi::petsc::IndexSpace<int>::IndexSpace(::esi::IndexSpace<int> &sourceIndexSpace)
16: {
17: int ierr,n,N;
18: MPI_Comm *icomm;
20: sourceIndexSpace.getRunTimeModel("MPI",reinterpret_cast<void *&>(icomm));if (ierr) return;
21: sourceIndexSpace.getGlobalSize(N);if (ierr) return;
22: {
23: ::esi::IndexSpace<int> *amap;
25: sourceIndexSpace.getInterface("esi::IndexSpace",reinterpret_cast<void *&>(amap));if (ierr) return;
26: amap->getLocalSize(n);if (ierr) return;
27: }
28: PetscMapCreateMPI(*icomm,n,N,&this->map);if (ierr) return;
29: PetscObjectGetComm((PetscObject)this->map,&this->comm);if (ierr) return;
30: }
32: esi::petsc::IndexSpace<int>::IndexSpace(PetscMap sourceIndexSpace)
33: {
34: PetscObjectReference((PetscObject) sourceIndexSpace);
35: this->map = sourceIndexSpace;
36: PetscObjectGetComm((PetscObject)sourceIndexSpace,&this->comm);
37: }
39: esi::petsc::IndexSpace<int>::~IndexSpace()
40: {
41: PetscMapDestroy(this->map);
42: }
44: /* ---------------esi::Object methods ------------------------------------------------------------ */
45: ::esi::ErrorCode esi::petsc::IndexSpace<int>::getInterface(const char* name, void *& iface)
46: {
47: PetscTruth flg;
48: if (PetscStrcmp(name,"esi::Object",&flg),flg){
49: iface = (void *) (::esi::Object *) this;
50: } else if (PetscStrcmp(name,"esi::IndexSpace",&flg),flg){
51: iface = (void *) (::esi::IndexSpace<int> *) this;
52: } else if (PetscStrcmp(name,"esi::petsc::IndexSpace",&flg),flg){
53: iface = (void *) (::esi::petsc::IndexSpace<int> *) this;
54: } else if (PetscStrcmp(name,"PetscMap",&flg),flg){
55: iface = (void *) this->map;
56: } else {
57: iface = 0;
58: }
59: return 0;
60: }
62: ::esi::ErrorCode esi::petsc::IndexSpace<int>::getInterfacesSupported(::esi::Argv * list)
63: {
64: list->appendArg("esi::Object");
65: list->appendArg("esi::IndexSpace");
66: list->appendArg("esi::petsc::IndexSpace");
67: list->appendArg("PetscMap");
68: return 0;
69: }
71: /* -------------- esi::IndexSpace methods --------------------------------------------*/
72: ::esi::ErrorCode esi::petsc::IndexSpace<int>::getGlobalSize(int &globalSize)
73: {
74: return PetscMapGetSize(this->map,&globalSize);
75: }
77: ::esi::ErrorCode esi::petsc::IndexSpace<int>::getLocalSize(int &localSize)
78: {
79: return PetscMapGetLocalSize(this->map,&localSize);
80: }
82: ::esi::ErrorCode esi::petsc::IndexSpace<int>::getLocalPartitionOffset(int &localoffset)
83: {
84: return PetscMapGetLocalRange(this->map,&localoffset,PETSC_IGNORE);
85: }
87: ::esi::ErrorCode esi::petsc::IndexSpace<int>::getGlobalPartitionOffsets(int *globaloffsets)
88: {
89: int ierr,*iglobaloffsets;
90: int size;
92: PetscMapGetGlobalRange(this->map,&iglobaloffsets);
93: MPI_Comm_size(this->comm,&size);
94: PetscMemcpy(globaloffsets,iglobaloffsets,(size+1)*sizeof(int));
95: return 0;
96: }
98: ::esi::ErrorCode esi::petsc::IndexSpace<int>::getGlobalPartitionSizes(int *globalsizes)
99: {
100: int ierr,i,n,*globalranges;
103: MPI_Comm_size(this->comm,&n);
104: PetscMapGetGlobalRange(this->map,&globalranges);
105: for (i=0; i<n; i++) {
106: globalsizes[i] = globalranges[i+1] - globalranges[i];
107: }
108: return 0;
109: }
111: /* -------------------------------------------------------------------------*/
113: // Construct a IndexSpace
114: ::esi::ErrorCode esi::petsc::IndexSpace<int>::Factory::create(const char * name,void *icomm,int m,int N,int base,::esi::IndexSpace<int>*&v)
115: {
116: PetscTruth ismpi;
117: int PetscStrcmp(name,"MPI",&ismpi);
118: if (!ismpi) SETERRQ1(1,"%s not supported, only MPI supported as RunTimeModel",name);
119: v = new esi::petsc::IndexSpace<int>(*(MPI_Comm*)icomm,m,N);
120: return 0;
121: };
123: EXTERN_C_BEGIN
124: ::esi::IndexSpace<int>::Factory *create_esi_petsc_indexspacefactory(void)
125: {
126: return dynamic_cast< ::esi::IndexSpace<int>::Factory* >(new esi::petsc::IndexSpace<int>::Factory);
127: }
128: EXTERN_C_END
130: /* ::esi::petsc::IndexSpaceFactory<int> ISFInstForIntel64CompilerBug; */
132: #if defined(PETSC_HAVE_TRILINOS)
133: #define PETRA_MPI /* used by Ptera to indicate MPI code */
134: #include "Petra_ESI_IndexSpace.h"
136: template<class Ordinal> class Petra_ESI_IndexSpaceFactory : public virtual ::esi::IndexSpace<Ordinal>::Factory
137: {
138: public:
140: // Destructor.
141: virtual ~Petra_ESI_IndexSpaceFactory(void){};
143: // Construct a IndexSpace
144: virtual ::esi::ErrorCode create(const char * name,void *comm,int m,int M,int base,::esi::IndexSpace<Ordinal>*&v)
145: {
146: PetscTruth ismpi;
147: int PetscStrcmp(name,"MPI",&ismpi);
148: if (!ismpi) SETERRQ1(1,"%s not supported, only MPI supported as RunTimeModel",name);
149: Petra_Comm *pcomm = new Petra_Comm(*(MPI_Comm*)comm);
150: v = new Petra_ESI_IndexSpace<Ordinal>(-1,m,0,*pcomm);
151: if (!v) SETERRQ(1,"Unable to create Petra_ESI_IndexSpace");
152: return 0;
153: };
155: };
156: EXTERN_C_BEGIN
157: ::esi::IndexSpace<int>Factory *create_petra_esi_indexspacefactory(void)
158: {
159: return dynamic_cast< ::esi::IndexSpace<int>Factory *>(new Petra_ESI_IndexSpaceFactory<int>);
160: }
161: EXTERN_C_END
162: #endif