/[escript]/branches/doubleplusgood/paso/src/SharedComponents.cpp
ViewVC logotype

Contents of /branches/doubleplusgood/paso/src/SharedComponents.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3259 - (show annotations)
Mon Oct 11 01:48:14 2010 UTC (8 years, 5 months ago) by jfenwick
Original Path: trunk/paso/src/SharedComponents.c
File MIME type: text/plain
File size: 3945 byte(s)
Merging dudley and scons updates from branches

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 /**************************************************************/
16
17 /* Paso: SharedComponents organizes the coupling with in a pattern/matrix */
18 /* across processors */
19
20 /**************************************************************/
21
22 /* Author: Lutz Gross, l.gross@uq.edu.au */
23
24 /**************************************************************/
25
26 #include "SharedComponents.h"
27 #include "esysUtils/error.h"
28
29 /**************************************************************/
30
31 /* allocates a SharedComponents */
32
33
34 /**************************************************************/
35
36 Paso_SharedComponents* Paso_SharedComponents_alloc(dim_t local_length,
37 dim_t numNeighbors,
38 Esys_MPI_rank* neighbor,
39 index_t* shared,
40 index_t* offsetInShared,
41 index_t m, index_t b,
42 Esys_MPIInfo *mpi_info)
43 {
44 dim_t i,j;
45 register index_t itmp;
46 Paso_SharedComponents* out=NULL;
47 Esys_resetError();
48 out=MEMALLOC(1,Paso_SharedComponents);
49 if (!Esys_checkPtr(out)) {
50 out->local_length=local_length*m;
51 out->mpi_info = Esys_MPIInfo_getReference(mpi_info);
52 out->numNeighbors=numNeighbors;
53 out->neighbor=MEMALLOC(out->numNeighbors,Esys_MPI_rank);
54 if (offsetInShared == NULL) {
55 out->numSharedComponents=0;
56 } else {
57 out->numSharedComponents=offsetInShared[numNeighbors]*m;
58 }
59 out->shared=MEMALLOC(out->numSharedComponents,index_t);
60 out->offsetInShared=MEMALLOC(out->numNeighbors+1,index_t);
61 out->reference_counter=1;
62 if (! (Esys_checkPtr(out->neighbor) ||
63 Esys_checkPtr(out->shared) ||
64 Esys_checkPtr(out->offsetInShared) ) ) {
65
66
67 if ((out->numNeighbors>0) && (offsetInShared!=NULL) ) {
68 #pragma omp parallel
69 {
70 #pragma omp for private(i)
71 for (i=0;i<out->numNeighbors;++i){
72 out->neighbor[i]=neighbor[i];
73 out->offsetInShared[i]=offsetInShared[i]*m;
74 }
75 out->offsetInShared[out->numNeighbors]=offsetInShared[numNeighbors]*m;
76 #pragma omp for private(i,j,itmp)
77 for (i=0;i<offsetInShared[numNeighbors];++i){
78 itmp=m*shared[i]+b;
79 for (j=0;j<m;++j) out->shared[m*i+j]=itmp+j;
80 }
81 }
82 } else {
83 out->offsetInShared[out->numNeighbors]=0;
84 }
85 }
86
87 }
88 if (Esys_noError()) {
89 return out;
90 } else {
91 Paso_SharedComponents_free(out);
92 return NULL;
93 }
94 }
95
96 /* returns a reference to in */
97
98 Paso_SharedComponents* Paso_SharedComponents_getReference(Paso_SharedComponents* in) {
99 if (in!=NULL) {
100 ++(in->reference_counter);
101 }
102 return in;
103 }
104
105 /* deallocates a SharedComponents: */
106
107 void Paso_SharedComponents_free(Paso_SharedComponents* in) {
108 if (in!=NULL) {
109 in->reference_counter--;
110 if (in->reference_counter<=0) {
111 MEMFREE(in->neighbor);
112 MEMFREE(in->shared);
113 MEMFREE(in->offsetInShared);
114 Esys_MPIInfo_free(in->mpi_info);
115 MEMFREE(in);
116 #ifdef Paso_TRACE
117 printf("Paso_SharedComponents_dealloc: system matrix pattern as been deallocated.\n");
118 #endif
119 }
120 }
121 }

  ViewVC Help
Powered by ViewVC 1.1.26