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

  ViewVC Help
Powered by ViewVC 1.1.26