~vcs-imports/escript-finley/trunk

« back to all changes in this revision

Viewing changes to paso/src/Coupler.c

  • Committer: jfenwick
  • Date: 2010-10-11 01:48:14 UTC
  • Revision ID: svn-v4:77569008-7704-0410-b7a0-a92fef0b09fd:trunk:3259
Merging dudley and scons updates from branches

Show diffs side-by-side

added added

removed removed

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