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

Contents of /trunk-mpi-branch/finley/src/NodeFile_gather.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1267 - (show annotations)
Tue Aug 21 22:01:21 2007 UTC (12 years, 9 months ago) by gross
File MIME type: text/plain
File size: 9370 byte(s)
check for preperation status removed. is not really needed.
1 /*
2 ************************************************************
3 * Copyright 2006 by ACcESS MNRF *
4 * *
5 * http://www.access.edu.au *
6 * Primary Business: Queensland, Australia *
7 * Licensed under the Open Software License version 3.0 *
8 * http://www.opensource.org/licenses/osl-3.0.php *
9 * *
10 ************************************************************
11 */
12
13 /**************************************************************/
14
15 /* Finley: Mesh: NodeFile */
16
17 /* gathers the NodeFile out from the NodeFile in using the entries
18 /* in index[0:out->numNodes-1] which are between min_index and max_index (exclusive) */
19 /* the node index[i]
20
21 /**************************************************************/
22
23 /* Author: gross@access.edu.au */
24 /* Version: $Id$ */
25
26 /**************************************************************/
27
28 #include "NodeFile.h"
29
30 /**************************************************************/
31
32 void Finley_NodeFile_gatherEntries(dim_t n, index_t* index, index_t min_index, index_t max_index,
33 index_t* Id_out, index_t* Id_in,
34 index_t* Tag_out, index_t* Tag_in,
35 index_t* globalDegreesOfFreedom_out, index_t* globalDegreesOfFreedom_in,
36 dim_t numDim, double* Coordinates_out, double* Coordinates_in)
37 {
38 dim_t i,j;
39 register index_t k;
40 register const index_t range=max_index-min_index;
41 const size_t numDim_size=(size_t)numDim*sizeof(double);
42
43 #pragma omp parallel for private(i,j,k) schedule(static)
44 for (i=0;i<n;i++) {
45 k=index[i]-min_index;
46 if ((k>=0) && (k <range)) {
47 Id_out[i]=Id_in[k];
48 Tag_out[i]=Tag_in[k];
49 globalDegreesOfFreedom_out[i]=globalDegreesOfFreedom_in[k];
50 memcpy(&(Coordinates_out[INDEX2(0,i,numDim)]), &(Coordinates_in[INDEX2(0,k,numDim)]), numDim_size);
51 }
52 }
53 }
54
55 void Finley_NodeFile_gather(index_t* index, Finley_NodeFile* in, Finley_NodeFile* out)
56 {
57 index_t min_id, max_id;
58 Finley_NodeFile_setGlobalIdRange(&min_id,&max_id,in);
59 Finley_NodeFile_gatherEntries(out->numNodes, index, min_id, max_id,
60 out->Id, in->Id,
61 out->Tag, in->Tag,
62 out->globalDegreesOfFreedom, in->globalDegreesOfFreedom,
63 out->numDim, out->Coordinates, in->Coordinates);
64 }
65
66 void Finley_NodeFile_gather_global(index_t* index, Finley_NodeFile* in, Finley_NodeFile* out)
67 {
68 index_t min_id, max_id, undefined_node;
69 Paso_MPI_rank buffer_rank, dest, source, *distribution=NULL;
70 index_t *Id_buffer=NULL, *Tag_buffer=NULL, *globalDegreesOfFreedom_buffer=NULL;
71 double* Coordinates_buffer=NULL;
72 dim_t p, buffer_len,n;
73 char error_msg[100];
74 #ifdef PASO_MPI
75 MPI_Status status;
76 #endif
77
78 /* get the global range of node ids */
79 Finley_NodeFile_setGlobalIdRange(&min_id,&max_id,in);
80 undefined_node=min_id-1;
81
82 distribution=TMPMEMALLOC(in->MPIInfo->size+1, index_t);
83
84 if ( !Finley_checkPtr(distribution) ) {
85 /* distribute the range of node ids */
86 buffer_len=Paso_MPIInfo_setDistribution(in->MPIInfo,min_id,max_id,distribution);
87 /* allocate buffers */
88 Id_buffer=TMPMEMALLOC(buffer_len,index_t);
89 Tag_buffer=TMPMEMALLOC(buffer_len,index_t);
90 globalDegreesOfFreedom_buffer=TMPMEMALLOC(buffer_len,index_t);
91 Coordinates_buffer=TMPMEMALLOC(buffer_len*out->numDim,double);
92 if (! (Finley_checkPtr(Id_buffer) || Finley_checkPtr(Tag_buffer) ||
93 Finley_checkPtr(globalDegreesOfFreedom_buffer) || Finley_checkPtr(Coordinates_buffer) ) ) {
94 /* fill Id_buffer by the undefined_node marker to check if nodes are defined */
95 #pragma omp parallel for private(n) schedule(static)
96 for (n=0;n<buffer_len;n++) Id_buffer[n]=undefined_node;
97
98 /* fill the buffer by sending portions around in a circle */
99 dest=Paso_MPIInfo_mod(in->MPIInfo->size, in->MPIInfo->rank + 1);
100 source=Paso_MPIInfo_mod(in->MPIInfo->size, in->MPIInfo->rank - 1);
101 buffer_rank=in->MPIInfo->rank;
102 for (p=0; p< in->MPIInfo->size; ++p) {
103 if (p>0) { /* the initial send can be skipped */
104 #ifdef PASO_MPI
105 MPI_Sendrecv_replace(Id_buffer, buffer_len, MPI_INT,
106 dest, in->MPIInfo->msg_tag_counter, source, in->MPIInfo->msg_tag_counter,
107 in->MPIInfo->comm,&status);
108 MPI_Sendrecv_replace(Tag_buffer, buffer_len, MPI_INT,
109 dest, in->MPIInfo->msg_tag_counter+1, source, in->MPIInfo->msg_tag_counter+1,
110 in->MPIInfo->comm,&status);
111 MPI_Sendrecv_replace(globalDegreesOfFreedom_buffer, buffer_len, MPI_INT,
112 dest, in->MPIInfo->msg_tag_counter+2, source, in->MPIInfo->msg_tag_counter+2,
113 in->MPIInfo->comm,&status);
114 MPI_Sendrecv_replace(Coordinates_buffer, buffer_len*out->numDim, MPI_DOUBLE,
115 dest, in->MPIInfo->msg_tag_counter+3, source, in->MPIInfo->msg_tag_counter+3,
116 in->MPIInfo->comm,&status);
117 #endif
118 in->MPIInfo->msg_tag_counter+=4;
119 }
120 buffer_rank=Paso_MPIInfo_mod(in->MPIInfo->size, buffer_rank-1);
121 Finley_NodeFile_scatterEntries(in->numNodes, in->Id,
122 distribution[buffer_rank], distribution[buffer_rank+1],
123 Id_buffer, in->Id,
124 Tag_buffer, in->Tag,
125 globalDegreesOfFreedom_buffer, in->globalDegreesOfFreedom,
126 out->numDim, Coordinates_buffer, in->Coordinates);
127 }
128 /* now entries are collected from the buffer again by sending the entries around in a circle */
129 dest=Paso_MPIInfo_mod(in->MPIInfo->size, in->MPIInfo->rank + 1);
130 source=Paso_MPIInfo_mod(in->MPIInfo->size, in->MPIInfo->rank - 1);
131 buffer_rank=in->MPIInfo->rank;
132 for (p=0; p< in->MPIInfo->size; ++p) {
133 Finley_NodeFile_gatherEntries(out->numNodes, index,
134 distribution[buffer_rank], distribution[buffer_rank+1],
135 out->Id, Id_buffer,
136 out->Tag, Tag_buffer,
137 out->globalDegreesOfFreedom, globalDegreesOfFreedom_buffer,
138 out->numDim, out->Coordinates, Coordinates_buffer);
139 if (p<in->MPIInfo->size-1) { /* the last send can be skipped */
140 #ifdef PASO_MPI
141 MPI_Sendrecv_replace(Id_buffer, buffer_len, MPI_INT,
142 dest, in->MPIInfo->msg_tag_counter, source, in->MPIInfo->msg_tag_counter,
143 in->MPIInfo->comm,&status);
144 MPI_Sendrecv_replace(Tag_buffer, buffer_len, MPI_INT,
145 dest, in->MPIInfo->msg_tag_counter+1, source, in->MPIInfo->msg_tag_counter+1,
146 in->MPIInfo->comm,&status);
147 MPI_Sendrecv_replace(globalDegreesOfFreedom_buffer, buffer_len, MPI_INT,
148 dest, in->MPIInfo->msg_tag_counter+2, source, in->MPIInfo->msg_tag_counter+2,
149 in->MPIInfo->comm,&status);
150 MPI_Sendrecv_replace(Coordinates_buffer, buffer_len*out->numDim, MPI_DOUBLE,
151 dest, in->MPIInfo->msg_tag_counter+3, source, in->MPIInfo->msg_tag_counter+3,
152 in->MPIInfo->comm,&status);
153 #endif
154 in->MPIInfo->msg_tag_counter+=4;
155 }
156 buffer_rank=Paso_MPIInfo_mod(in->MPIInfo->size, buffer_rank-1);
157 }
158 /* check if all nodes are set: */
159 #pragma omp parallel for private(n) schedule(static)
160 for (n=0; n< out->numNodes; ++n) {
161 if (out->Id[n] == undefined_node ) {
162 sprintf(error_msg,"Finley_NodeFile_gather_global: Node id %d is referenced but is not defined.",out->Id[n]);
163 Finley_setError(VALUE_ERROR,error_msg);
164 }
165 }
166
167 }
168 TMPMEMFREE(Id_buffer);
169 TMPMEMFREE(Tag_buffer);
170 TMPMEMFREE(globalDegreesOfFreedom_buffer);
171 TMPMEMFREE(Coordinates_buffer);
172 }
173 TMPMEMFREE(distribution);
174 /* make sure that the error is global */
175 Paso_MPIInfo_noError(in->MPIInfo);
176 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26