/[escript]/trunk/finley/src/NodeFile_gather.c
ViewVC logotype

Diff of /trunk/finley/src/NodeFile_gather.c

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

trunk/esys2/finley/src/finleyC/NodeFile_gatter.c revision 150 by jgs, Thu Sep 15 03:44:45 2005 UTC trunk/finley/src/NodeFile_gather.c revision 1739 by gross, Fri Aug 29 06:19:53 2008 UTC
# Line 1  Line 1 
 /*  
  ******************************************************************************  
  *                                                                            *  
  *       COPYRIGHT  ACcESS 2003,2004,2005 -  All Rights Reserved              *  
  *                                                                            *  
  * This software is the property of ACcESS. No part of this code              *  
  * may be copied in any form or by any means without the expressed written    *  
  * consent of ACcESS.  Copying, use or modification of this software          *  
  * by any unauthorised person is illegal unless that person has a software    *  
  * license agreement with ACcESS.                                             *  
  *                                                                            *  
  ******************************************************************************  
 */  
1    
2  /**************************************************************/  /* $Id$ */
   
 /*   Finley: Mesh: NodeFile                                   */  
   
 /*   gathers the NodeFile out from the  NodeFile in using index[0:out->numNodes-1].  */  
 /*   index has to be between 0 and in->numNodes-1. */  
3    
4  /**************************************************************/  /*******************************************************
5     *
6  /*   Author: gross@access.edu.au */   *           Copyright 2003-2007 by ACceSS MNRF
7  /*   Version: $Id$ */   *       Copyright 2007 by University of Queensland
8     *
9  /**************************************************************/   *                http://esscc.uq.edu.au
10     *        Primary Business: Queensland, Australia
11     *  Licensed under the Open Software License version 3.0
12     *     http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16    /**************************************************************
17     *
18     *   Finley: Mesh: NodeFile                                  
19     *   gathers the NodeFile out from the NodeFile in using the entries
20     *   in index[0:out->numNodes-1] which are between min_index and max_index (exclusive)
21     *   the node index[i]
22     *
23     **************************************************************/
24    
25  #include "NodeFile.h"  #include "NodeFile.h"
26    
27  /**************************************************************/  /**************************************************************/
28    
29  void Finley_NodeFile_gather(int* index, Finley_NodeFile* in, Finley_NodeFile* out) {  void Finley_NodeFile_gatherEntries(dim_t n, index_t* index, index_t min_index, index_t max_index,
30     dim_t i,j;                                     index_t* Id_out, index_t* Id_in,
31     index_t k;                                     index_t* Tag_out, index_t* Tag_in,
32     if (in->Id!=NULL) {                                     index_t* globalDegreesOfFreedom_out, index_t* globalDegreesOfFreedom_in,
33       #pragma omp parallel for private(i,j,k) schedule(static)                                     dim_t numDim, double* Coordinates_out, double* Coordinates_in)
34       for (i=0;i<out->numNodes;i++) {  {
35          k=index[i];     dim_t i;
36          out->Id[i]=in->Id[k];     register index_t k;
37          out->Tag[i]=in->Tag[k];     register const index_t range=max_index-min_index;
38          out->degreeOfFreedom[i]=in->degreeOfFreedom[k];     const  size_t numDim_size=(size_t)numDim*sizeof(double);
39          out->reducedDegreeOfFreedom[i]=in->reducedDegreeOfFreedom[k];  
40          out->toReduced[i]=in->toReduced[k];     #pragma omp parallel for private(i,k) schedule(static)
41          for(j=0;j<in->numDim;j++) out->Coordinates[INDEX2(j,i,in->numDim)]=in->Coordinates[INDEX2(j,k,in->numDim)];     for (i=0;i<n;i++) {
42       }        k=index[i]-min_index;
43          if ((k>=0) && (k <range)) {
44             Id_out[i]=Id_in[k];
45             Tag_out[i]=Tag_in[k];
46             globalDegreesOfFreedom_out[i]=globalDegreesOfFreedom_in[k];
47             memcpy(&(Coordinates_out[INDEX2(0,i,numDim)]), &(Coordinates_in[INDEX2(0,k,numDim)]), numDim_size);
48          }
49     }     }
50  }  }
51  /*  
52  * $Log$  void Finley_NodeFile_gather(index_t* index, Finley_NodeFile* in, Finley_NodeFile* out)
53  * Revision 1.3  2005/09/15 03:44:23  jgs  {
54  * Merge of development branch dev-02 back to main trunk on 2005-09-15     index_t min_id, max_id;
55  *     Finley_NodeFile_setGlobalIdRange(&min_id,&max_id,in);
56  * Revision 1.2.2.1  2005/09/07 06:26:20  gross     Finley_NodeFile_gatherEntries(out->numNodes, index, min_id, max_id,
57  * the solver from finley are put into the standalone package paso now                                   out->Id, in->Id,
58  *                                   out->Tag, in->Tag,
59  * Revision 1.2  2005/07/08 04:07:55  jgs                                   out->globalDegreesOfFreedom, in->globalDegreesOfFreedom,
60  * Merge of development branch back to main trunk on 2005-07-08                                   out->numDim, out->Coordinates, in->Coordinates);
61  *  }
62  * Revision 1.1.1.1.2.1  2005/06/29 02:34:54  gross  
63  * some changes towards 64 integers in finley  void Finley_NodeFile_gather_global(index_t* index, Finley_NodeFile* in, Finley_NodeFile* out)
64  *  {
65  * Revision 1.1.1.1  2004/10/26 06:53:57  jgs    index_t min_id, max_id, undefined_node;
66  * initial import of project esys2    Paso_MPI_rank buffer_rank, dest, source, *distribution=NULL;
67  *    index_t  *Id_buffer=NULL, *Tag_buffer=NULL, *globalDegreesOfFreedom_buffer=NULL;
68  * Revision 1.1.1.1  2004/06/24 04:00:40  johng    double* Coordinates_buffer=NULL;
69  * Initial version of eys using boost-python.    dim_t p, buffer_len,n;
70  *    char error_msg[100];
71  *    #ifdef PASO_MPI
72  */    MPI_Status status;
73      #endif
74    
75      /* get the global range of node ids */
76      Finley_NodeFile_setGlobalIdRange(&min_id,&max_id,in);
77      undefined_node=min_id-1;
78    
79      distribution=TMPMEMALLOC(in->MPIInfo->size+1, index_t);
80    
81      if ( !Finley_checkPtr(distribution) ) {
82          /* distribute the range of node ids */
83          buffer_len=Paso_MPIInfo_setDistribution(in->MPIInfo,min_id,max_id,distribution);
84          /* allocate buffers */
85          Id_buffer=TMPMEMALLOC(buffer_len,index_t);
86          Tag_buffer=TMPMEMALLOC(buffer_len,index_t);
87          globalDegreesOfFreedom_buffer=TMPMEMALLOC(buffer_len,index_t);
88          Coordinates_buffer=TMPMEMALLOC(buffer_len*out->numDim,double);
89          if (! (Finley_checkPtr(Id_buffer) || Finley_checkPtr(Tag_buffer) ||
90                         Finley_checkPtr(globalDegreesOfFreedom_buffer) || Finley_checkPtr(Coordinates_buffer) ) ) {
91                /* fill Id_buffer by the undefined_node marker to check if nodes are defined */
92                #pragma omp parallel for private(n) schedule(static)
93                for (n=0;n<buffer_len;n++) Id_buffer[n]=undefined_node;
94                
95                /* fill the buffer by sending portions around in a circle */
96                dest=Paso_MPIInfo_mod(in->MPIInfo->size, in->MPIInfo->rank + 1);
97                source=Paso_MPIInfo_mod(in->MPIInfo->size, in->MPIInfo->rank - 1);
98                buffer_rank=in->MPIInfo->rank;
99                for (p=0; p< in->MPIInfo->size; ++p) {
100                     if (p>0) {  /* the initial send can be skipped */
101                         #ifdef PASO_MPI
102                         MPI_Sendrecv_replace(Id_buffer, buffer_len, MPI_INT,
103                                              dest, in->MPIInfo->msg_tag_counter, source, in->MPIInfo->msg_tag_counter,
104                                              in->MPIInfo->comm,&status);
105                         MPI_Sendrecv_replace(Tag_buffer, buffer_len, MPI_INT,
106                                              dest, in->MPIInfo->msg_tag_counter+1, source, in->MPIInfo->msg_tag_counter+1,
107                                              in->MPIInfo->comm,&status);
108                         MPI_Sendrecv_replace(globalDegreesOfFreedom_buffer, buffer_len, MPI_INT,
109                                              dest, in->MPIInfo->msg_tag_counter+2, source, in->MPIInfo->msg_tag_counter+2,
110                                              in->MPIInfo->comm,&status);
111                         MPI_Sendrecv_replace(Coordinates_buffer, buffer_len*out->numDim, MPI_DOUBLE,
112                                              dest, in->MPIInfo->msg_tag_counter+3, source, in->MPIInfo->msg_tag_counter+3,
113                                              in->MPIInfo->comm,&status);
114                         #endif
115                         in->MPIInfo->msg_tag_counter+=4;
116                     }
117                     buffer_rank=Paso_MPIInfo_mod(in->MPIInfo->size, buffer_rank-1);
118                     Finley_NodeFile_scatterEntries(in->numNodes, in->Id,
119                                                    distribution[buffer_rank], distribution[buffer_rank+1],
120                                                    Id_buffer, in->Id,
121                                                    Tag_buffer, in->Tag,
122                                                    globalDegreesOfFreedom_buffer, in->globalDegreesOfFreedom,
123                                                    out->numDim, Coordinates_buffer, in->Coordinates);
124                }
125                /* now entries are collected from the buffer again by sending the entries around in a circle */
126                dest=Paso_MPIInfo_mod(in->MPIInfo->size, in->MPIInfo->rank + 1);
127                source=Paso_MPIInfo_mod(in->MPIInfo->size, in->MPIInfo->rank - 1);
128                buffer_rank=in->MPIInfo->rank;
129                for (p=0; p< in->MPIInfo->size; ++p) {
130                     Finley_NodeFile_gatherEntries(out->numNodes, index,
131                                                   distribution[buffer_rank], distribution[buffer_rank+1],
132                                                   out->Id, Id_buffer,
133                                                   out->Tag, Tag_buffer,
134                                                   out->globalDegreesOfFreedom, globalDegreesOfFreedom_buffer,
135                                                   out->numDim, out->Coordinates, Coordinates_buffer);
136                     if (p<in->MPIInfo->size-1) {  /* the last send can be skipped */
137                         #ifdef PASO_MPI
138                         MPI_Sendrecv_replace(Id_buffer, buffer_len, MPI_INT,
139                                              dest, in->MPIInfo->msg_tag_counter, source, in->MPIInfo->msg_tag_counter,
140                                              in->MPIInfo->comm,&status);
141                         MPI_Sendrecv_replace(Tag_buffer, buffer_len, MPI_INT,
142                                              dest, in->MPIInfo->msg_tag_counter+1, source, in->MPIInfo->msg_tag_counter+1,
143                                              in->MPIInfo->comm,&status);
144                         MPI_Sendrecv_replace(globalDegreesOfFreedom_buffer, buffer_len, MPI_INT,
145                                              dest, in->MPIInfo->msg_tag_counter+2, source, in->MPIInfo->msg_tag_counter+2,
146                                              in->MPIInfo->comm,&status);
147                         MPI_Sendrecv_replace(Coordinates_buffer, buffer_len*out->numDim, MPI_DOUBLE,
148                                              dest, in->MPIInfo->msg_tag_counter+3, source, in->MPIInfo->msg_tag_counter+3,
149                                              in->MPIInfo->comm,&status);
150                         #endif
151                         in->MPIInfo->msg_tag_counter+=4;
152                     }
153                     buffer_rank=Paso_MPIInfo_mod(in->MPIInfo->size, buffer_rank-1);
154                }
155                /* check if all nodes are set: */
156                #pragma omp parallel for private(n) schedule(static)
157                for (n=0; n< out->numNodes; ++n) {
158                    if (out->Id[n] == undefined_node ) {
159                     sprintf(error_msg,"Finley_NodeFile_gather_global: Node id %d is referenced but is not defined.",out->Id[n]);
160                     Finley_setError(VALUE_ERROR,error_msg);
161                   }
162                 }
163    
164          }
165          TMPMEMFREE(Id_buffer);
166          TMPMEMFREE(Tag_buffer);
167          TMPMEMFREE(globalDegreesOfFreedom_buffer);
168          TMPMEMFREE(Coordinates_buffer);
169      }
170      TMPMEMFREE(distribution);
171      /* make sure that the error is global */
172      Paso_MPIInfo_noError(in->MPIInfo);
173    }

Legend:
Removed from v.150  
changed lines
  Added in v.1739

  ViewVC Help
Powered by ViewVC 1.1.26