/[escript]/trunk/paso/src/Coupler.h
ViewVC logotype

Diff of /trunk/paso/src/Coupler.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4816 by caltinay, Fri Mar 28 06:16:02 2014 UTC revision 4817 by caltinay, Fri Mar 28 08:04:09 2014 UTC
# Line 32  Line 32 
32    
33  namespace paso {  namespace paso {
34    
35    struct Connector;
36    typedef boost::shared_ptr<Connector> Connector_ptr;
37    typedef boost::shared_ptr<const Connector> const_Connector_ptr;
38    
39    struct Coupler;
40    typedef boost::shared_ptr<Coupler> Coupler_ptr;
41    typedef boost::shared_ptr<const Coupler> const_Coupler_ptr;
42    
43    PASO_DLL_API
44  struct Connector  struct Connector
45  {  {
46      SharedComponents_ptr send;      SharedComponents_ptr send;
47      SharedComponents_ptr recv;      SharedComponents_ptr recv;
     dim_t reference_counter;  
48      Esys_MPIInfo* mpi_info;      Esys_MPIInfo* mpi_info;
49    
50        Connector(SharedComponents_ptr s, SharedComponents_ptr r)
51        {
52            Esys_resetError();
53            if (s->mpi_info != r->mpi_info) {
54                Esys_setError(SYSTEM_ERROR,
55                        "Connector: send and recv MPI communicators don't match.");
56            } else if (s->local_length != r->local_length) {
57                Esys_setError(SYSTEM_ERROR,
58                        "Connector: local length of send and recv SharedComponents must match.");
59            }
60            send = s;
61            recv = r;
62            mpi_info = Esys_MPIInfo_getReference(s->mpi_info);
63        }
64    
65        /// destructor
66        ~Connector() { Esys_MPIInfo_free(mpi_info); }
67    
68        /// creates a copy
69        inline Connector_ptr copy() const { return unroll(1); }
70    
71        inline Connector_ptr unroll(index_t block_size) const
72        {
73            SharedComponents_ptr new_send_shcomp, new_recv_shcomp;
74            Connector_ptr out;
75            if (block_size > 1) {
76                new_send_shcomp.reset(new SharedComponents(send->local_length,
77                            send->numNeighbors, send->neighbor,
78                            send->shared, send->offsetInShared,
79                            block_size, 0, mpi_info));
80    
81                new_recv_shcomp.reset(new SharedComponents(recv->local_length,
82                        recv->numNeighbors, recv->neighbor,
83                        recv->shared, recv->offsetInShared,
84                        block_size, 0, mpi_info));
85            } else {
86                new_send_shcomp = send;
87                new_recv_shcomp = recv;
88            }
89            if (Esys_noError())
90                out.reset(new Connector(new_send_shcomp, new_recv_shcomp));
91            return out;
92        }
93    
94        //inline debug() const
95        //{
96        //    for (int i=0; i<recv->numNeighbors; ++i)
97        //        printf("Coupler: %d receive %d data at %d from %d\n",
98        //            s->mpi_info->rank,recv->offsetInShared[i+1]-recv->offsetInShared[i],
99        //            recv->offsetInShared[i],recv->neighbor[i]);
100        //    for (int i=0; i<send->numNeighbors; ++i)
101        //        printf("Coupler: %d send %d data at %d to %d\n",
102        //            s->mpi_info->rank,send->offsetInShared[i+1]-send->offsetInShared[i],
103        //            send->offsetInShared[i],send->neighbor[i]);
104        //}
105  };  };
106    
107    
108    PASO_DLL_API
109  struct Coupler  struct Coupler
110  {  {
111      Connector* connector;      Coupler(Connector_ptr, dim_t blockSize);
112        ~Coupler();
113    
114        void startCollect(const double* in);
115        double* finishCollect();
116        void copyAll(Coupler_ptr target) const;
117        void fillOverlap(dim_t n, double* x);
118        void max(dim_t n, double* x);
119    
120        inline const double* borrowLocalData() const { return data; }
121    
122        inline const double* borrowRemoteData() const { return recv_buffer; }
123    
124        inline dim_t getNumSharedComponents() const
125        {
126            return connector->send->numSharedComponents;
127        }
128    
129        inline dim_t getNumOverlapComponents() const
130        {
131            return connector->recv->numSharedComponents;
132        }
133    
134        inline dim_t getNumSharedValues() const
135        {
136            return getNumSharedComponents() * block_size;
137        }
138    
139        inline dim_t getNumOverlapValues() const
140        {
141            return getNumOverlapComponents() * block_size;
142        }
143    
144        inline dim_t getLocalLength() const
145        {
146            return connector->send->local_length;
147        }
148    
149        Connector_ptr connector;
150      dim_t block_size;      dim_t block_size;
151      bool in_use;      bool in_use;
152    
153      // unmanaged pointer to data to be sent      // unmanaged pointer to data to be sent
154      double *data;      double* data;
155      double *send_buffer;      double* send_buffer;
156      double *recv_buffer;      double* recv_buffer;
157      MPI_Request* mpi_requests;      MPI_Request* mpi_requests;
158      MPI_Status* mpi_stati;      MPI_Status* mpi_stati;
159          Esys_MPIInfo* mpi_info;
     dim_t reference_counter;  
     Esys_MPIInfo *mpi_info;  
160  };  };
161    
162    
 PASO_DLL_API  
 Connector* Connector_alloc(SharedComponents_ptr send, SharedComponents_ptr recv);  
   
 PASO_DLL_API  
 Connector* Connector_getReference(Connector*);  
   
 PASO_DLL_API  
 Connector* Connector_unroll(Connector* in, index_t block_size);  
   
 PASO_DLL_API  
 Connector* Connector_copy(Connector* in);  
   
 PASO_DLL_API  
 void Connector_free(Connector*);  
   
   
 PASO_DLL_API  
 Coupler* Coupler_alloc(Connector*, dim_t blockSize);  
   
 PASO_DLL_API  
 Coupler* Coupler_getReference(Coupler*);  
   
 PASO_DLL_API  
 void Coupler_startCollect(Coupler*, const double* in);  
   
 PASO_DLL_API  
 double* Coupler_finishCollect(Coupler*);  
   
 PASO_DLL_API  
 void Coupler_free(Coupler*);  
   
 PASO_DLL_API  
 void Coupler_copyAll(const Coupler* src, Coupler* target);  
   
 PASO_DLL_API  
 void Coupler_fillOverlap(dim_t n, double* x, Coupler* coupler);  
   
 PASO_DLL_API  
 void Coupler_max(dim_t n, double* x, Coupler* coupler);  
   
 inline const double* Coupler_borrowLocalData(const Coupler* in)  
 {  
     return in->data;  
 }  
   
 inline const double* Coupler_borrowRemoteData(const Coupler* in)  
 {  
     return in->recv_buffer;  
 }  
   
 inline dim_t Coupler_getNumSharedComponents(const Coupler* in)  
 {  
     return in->connector->send->numSharedComponents;  
 }  
   
 inline dim_t Coupler_getNumOverlapComponents(const Coupler* in)  
 {  
     return in->connector->recv->numSharedComponents;  
 }  
   
 inline dim_t Coupler_getNumSharedValues(const Coupler* in)  
 {  
     return Coupler_getNumSharedComponents(in) * in->block_size;  
 }  
   
 inline dim_t Coupler_getNumOverlapValues(const Coupler* in)  
 {  
     return Coupler_getNumOverlapComponents(in) * in->block_size;  
 }  
   
 inline dim_t Coupler_getLocalLength(const Coupler* in)  
 {  
     return in->connector->send->local_length;  
 }  
   
163  } // namespace paso  } // namespace paso
164    
165  #endif // __PASO_COUPLER_H__  #endif // __PASO_COUPLER_H__

Legend:
Removed from v.4816  
changed lines
  Added in v.4817

  ViewVC Help
Powered by ViewVC 1.1.26