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

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

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

revision 3258 by jfenwick, Thu Jan 28 02:03:15 2010 UTC revision 3259 by jfenwick, Mon Oct 11 01:48:14 2010 UTC
# Line 13  Line 13 
13    
14    
15  #include "Coupler.h"  #include "Coupler.h"
16    #include "esysUtils/error.h"
17    
18  /*************************************************************  /*************************************************************
19   *   *
# Line 24  Paso_Connector* Paso_Connector_alloc(Pas Line 25  Paso_Connector* Paso_Connector_alloc(Pas
25                                       Paso_SharedComponents* recv)                                       Paso_SharedComponents* recv)
26  {  {
27    Paso_Connector*out=NULL;    Paso_Connector*out=NULL;
28    Paso_resetError();    Esys_resetError();
29    out=MEMALLOC(1,Paso_Connector);    out=MEMALLOC(1,Paso_Connector);
30    if ( send->mpi_info != recv->mpi_info ) {    if ( send->mpi_info != recv->mpi_info ) {
31       Paso_setError(SYSTEM_ERROR,"Paso_Coupler_alloc: send and recv mpi communicator don't match.");       Esys_setError(SYSTEM_ERROR,"Paso_Coupler_alloc: send and recv mpi communicator don't match.");
32       return NULL;       return NULL;
33    }    }
34    if ( send->local_length != recv->local_length ) {    if ( send->local_length != recv->local_length ) {
35       Paso_setError(SYSTEM_ERROR,"Paso_Coupler_alloc: local length of send and recv Paso_SharedComponents must match.");       Esys_setError(SYSTEM_ERROR,"Paso_Coupler_alloc: local length of send and recv Paso_SharedComponents must match.");
36       return NULL;       return NULL;
37    }    }
38        
39    if (!Paso_checkPtr(out)) {    if (!Esys_checkPtr(out)) {
40        out->send=Paso_SharedComponents_getReference(send);        out->send=Paso_SharedComponents_getReference(send);
41        out->recv= Paso_SharedComponents_getReference(recv);        out->recv= Paso_SharedComponents_getReference(recv);
42        out->mpi_info = Paso_MPIInfo_getReference(send->mpi_info);        out->mpi_info = Esys_MPIInfo_getReference(send->mpi_info);
43        out->reference_counter=1;        out->reference_counter=1;
44    
45  /*  /*
# Line 53  out->send->offsetInShared[i],out->send-> Line 54  out->send->offsetInShared[i],out->send->
54  */  */
55    
56    }    }
57    if (Paso_noError()) {    if (Esys_noError()) {
58       return out;       return out;
59    } else {    } else {
60       Paso_Connector_free(out);       Paso_Connector_free(out);
# Line 78  void Paso_Connector_free(Paso_Connector* Line 79  void Paso_Connector_free(Paso_Connector*
79       if (in->reference_counter<=0) {       if (in->reference_counter<=0) {
80          Paso_SharedComponents_free(in->send);          Paso_SharedComponents_free(in->send);
81          Paso_SharedComponents_free(in->recv);          Paso_SharedComponents_free(in->recv);
82          Paso_MPIInfo_free(in->mpi_info);          Esys_MPIInfo_free(in->mpi_info);
83          MEMFREE(in);          MEMFREE(in);
84          #ifdef Paso_TRACE          #ifdef Paso_TRACE
85          printf("Paso_Coupler_dealloc: system matrix pattern as been deallocated.\n");          printf("Paso_Coupler_dealloc: system matrix pattern as been deallocated.\n");
# Line 94  Paso_Connector* Paso_Connector_copy(Paso Line 95  Paso_Connector* Paso_Connector_copy(Paso
95  Paso_Connector* Paso_Connector_unroll(Paso_Connector* in, index_t block_size) {  Paso_Connector* Paso_Connector_unroll(Paso_Connector* in, index_t block_size) {
96       Paso_SharedComponents *new_send_shcomp=NULL, *new_recv_shcomp=NULL;       Paso_SharedComponents *new_send_shcomp=NULL, *new_recv_shcomp=NULL;
97       Paso_Connector *out=NULL;       Paso_Connector *out=NULL;
98       if (Paso_noError()) {       if (Esys_noError()) {
99          if (block_size>1) {          if (block_size>1) {
100              new_send_shcomp=Paso_SharedComponents_alloc(in->send->local_length,              new_send_shcomp=Paso_SharedComponents_alloc(in->send->local_length,
101                                                          in->send->numNeighbors,                                                          in->send->numNeighbors,
# Line 113  Paso_Connector* Paso_Connector_unroll(Pa Line 114  Paso_Connector* Paso_Connector_unroll(Pa
114              new_send_shcomp=Paso_SharedComponents_getReference(in->send);              new_send_shcomp=Paso_SharedComponents_getReference(in->send);
115              new_recv_shcomp=Paso_SharedComponents_getReference(in->recv);              new_recv_shcomp=Paso_SharedComponents_getReference(in->recv);
116          }          }
117          if (Paso_noError()) out=Paso_Connector_alloc(new_send_shcomp,new_recv_shcomp);          if (Esys_noError()) out=Paso_Connector_alloc(new_send_shcomp,new_recv_shcomp);
118       }       }
119       Paso_SharedComponents_free(new_send_shcomp);       Paso_SharedComponents_free(new_send_shcomp);
120       Paso_SharedComponents_free(new_recv_shcomp);       Paso_SharedComponents_free(new_recv_shcomp);
121       if (Paso_noError()) {       if (Esys_noError()) {
122            return out;            return out;
123       } else {       } else {
124            Paso_Connector_free(out);            Paso_Connector_free(out);
# Line 132  Paso_Connector* Paso_Connector_unroll(Pa Line 133  Paso_Connector* Paso_Connector_unroll(Pa
133    
134  Paso_Coupler* Paso_Coupler_alloc(Paso_Connector* connector, dim_t block_size)  Paso_Coupler* Paso_Coupler_alloc(Paso_Connector* connector, dim_t block_size)
135  {  {
136    Paso_MPIInfo *mpi_info = connector->mpi_info;      Esys_MPIInfo *mpi_info = connector->mpi_info;  
137    Paso_Coupler*out=NULL;    Paso_Coupler*out=NULL;
138    Paso_resetError();    Esys_resetError();
139    out=MEMALLOC(1,Paso_Coupler);    out=MEMALLOC(1,Paso_Coupler);
140    if (!Paso_checkPtr(out)) {    if (!Esys_checkPtr(out)) {
141        out->data=NULL;        out->data=NULL;
142        out->block_size=block_size;        out->block_size=block_size;
143        out->connector=Paso_Connector_getReference(connector);        out->connector=Paso_Connector_getReference(connector);
# Line 144  Paso_Coupler* Paso_Coupler_alloc(Paso_Co Line 145  Paso_Coupler* Paso_Coupler_alloc(Paso_Co
145        out->recv_buffer=NULL;        out->recv_buffer=NULL;
146        out->mpi_requests=NULL;        out->mpi_requests=NULL;
147        out->mpi_stati=NULL;        out->mpi_stati=NULL;
148        out->mpi_info = Paso_MPIInfo_getReference(mpi_info);        out->mpi_info = Esys_MPIInfo_getReference(mpi_info);
149        out->reference_counter=1;        out->reference_counter=1;
150                
151        #ifdef PASO_MPI        #ifdef ESYS_MPI
152           out->mpi_requests=MEMALLOC(connector->send->numNeighbors+connector->recv->numNeighbors,MPI_Request);           out->mpi_requests=MEMALLOC(connector->send->numNeighbors+connector->recv->numNeighbors,MPI_Request);
153           out->mpi_stati=MEMALLOC(connector->send->numNeighbors+connector->recv->numNeighbors,MPI_Status);           out->mpi_stati=MEMALLOC(connector->send->numNeighbors+connector->recv->numNeighbors,MPI_Status);
154           Paso_checkPtr(out->mpi_requests);           Esys_checkPtr(out->mpi_requests);
155           Paso_checkPtr(out->mpi_stati);           Esys_checkPtr(out->mpi_stati);
156        #endif        #endif
157        if (mpi_info->size>1) {        if (mpi_info->size>1) {
158          out->send_buffer=MEMALLOC(connector->send->numSharedComponents * block_size,double);          out->send_buffer=MEMALLOC(connector->send->numSharedComponents * block_size,double);
159          out->recv_buffer=MEMALLOC(connector->recv->numSharedComponents * block_size,double);          out->recv_buffer=MEMALLOC(connector->recv->numSharedComponents * block_size,double);
160          Paso_checkPtr(out->send_buffer);          Esys_checkPtr(out->send_buffer);
161          Paso_checkPtr(out->recv_buffer);          Esys_checkPtr(out->recv_buffer);
162        }        }
163    }    }
164    if (Paso_noError()) {    if (Esys_noError()) {
165       return out;       return out;
166    } else {    } else {
167       Paso_Coupler_free(out);       Paso_Coupler_free(out);
# Line 188  void Paso_Coupler_free(Paso_Coupler* in) Line 189  void Paso_Coupler_free(Paso_Coupler* in)
189          MEMFREE(in->recv_buffer);          MEMFREE(in->recv_buffer);
190          MEMFREE(in->mpi_requests);          MEMFREE(in->mpi_requests);
191          MEMFREE(in->mpi_stati);          MEMFREE(in->mpi_stati);
192          Paso_MPIInfo_free(in->mpi_info);          Esys_MPIInfo_free(in->mpi_info);
193          MEMFREE(in);          MEMFREE(in);
194          #ifdef Paso_TRACE          #ifdef Paso_TRACE
195          printf("Paso_Coupler_dealloc: system matrix pattern as been deallocated.\n");          printf("Paso_Coupler_dealloc: system matrix pattern as been deallocated.\n");
# Line 200  void Paso_Coupler_free(Paso_Coupler* in) Line 201  void Paso_Coupler_free(Paso_Coupler* in)
201    
202  void Paso_Coupler_startCollect(Paso_Coupler* coupler,const double* in)  void Paso_Coupler_startCollect(Paso_Coupler* coupler,const double* in)
203  {  {
204    Paso_MPIInfo *mpi_info = coupler->mpi_info;      Esys_MPIInfo *mpi_info = coupler->mpi_info;  
205    dim_t block_size=coupler->block_size;    dim_t block_size=coupler->block_size;
206    size_t block_size_size=block_size*sizeof(double);    size_t block_size_size=block_size*sizeof(double);
207    dim_t i;    dim_t i;
# Line 209  void Paso_Coupler_startCollect(Paso_Coup Line 210  void Paso_Coupler_startCollect(Paso_Coup
210       /* start reveiving input */       /* start reveiving input */
211       {       {
212          for (i=0; i< coupler->connector->recv->numNeighbors; ++i) {          for (i=0; i< coupler->connector->recv->numNeighbors; ++i) {
213              #ifdef PASO_MPI              #ifdef ESYS_MPI
214              MPI_Irecv(&(coupler->recv_buffer[coupler->connector->recv->offsetInShared[i] *  block_size]),              MPI_Irecv(&(coupler->recv_buffer[coupler->connector->recv->offsetInShared[i] *  block_size]),
215                        (coupler->connector->recv->offsetInShared[i+1]- coupler->connector->recv->offsetInShared[i])*block_size,                        (coupler->connector->recv->offsetInShared[i+1]- coupler->connector->recv->offsetInShared[i])*block_size,
216                        MPI_DOUBLE,                        MPI_DOUBLE,
# Line 234  void Paso_Coupler_startCollect(Paso_Coup Line 235  void Paso_Coupler_startCollect(Paso_Coup
235       /* send buffer out */       /* send buffer out */
236       {       {
237          for (i=0; i< coupler->connector->send->numNeighbors; ++i) {          for (i=0; i< coupler->connector->send->numNeighbors; ++i) {
238               #ifdef PASO_MPI               #ifdef ESYS_MPI
239               MPI_Issend(&(coupler->send_buffer[coupler->connector->send->offsetInShared[i] *  block_size]),               MPI_Issend(&(coupler->send_buffer[coupler->connector->send->offsetInShared[i] *  block_size]),
240                          (coupler->connector->send->offsetInShared[i+1]- coupler->connector->send->offsetInShared[i])*block_size,                          (coupler->connector->send->offsetInShared[i+1]- coupler->connector->send->offsetInShared[i])*block_size,
241                          MPI_DOUBLE,                          MPI_DOUBLE,
# Line 251  void Paso_Coupler_startCollect(Paso_Coup Line 252  void Paso_Coupler_startCollect(Paso_Coup
252    
253  double* Paso_Coupler_finishCollect(Paso_Coupler* coupler)  double* Paso_Coupler_finishCollect(Paso_Coupler* coupler)
254  {  {
255    Paso_MPIInfo *mpi_info = coupler->mpi_info;      Esys_MPIInfo *mpi_info = coupler->mpi_info;  
256    if ( mpi_info->size>1) {    if ( mpi_info->size>1) {
257       /* wait for receive */       /* wait for receive */
258          #ifdef PASO_MPI          #ifdef ESYS_MPI
259          MPI_Waitall(coupler->connector->recv->numNeighbors+coupler->connector->send->numNeighbors,          MPI_Waitall(coupler->connector->recv->numNeighbors+coupler->connector->send->numNeighbors,
260                      coupler->mpi_requests,                      coupler->mpi_requests,
261                      coupler->mpi_stati);                      coupler->mpi_stati);

Legend:
Removed from v.3258  
changed lines
  Added in v.3259

  ViewVC Help
Powered by ViewVC 1.1.26