/[escript]/trunk/paso/src/SharedComponents.c
ViewVC logotype

Contents of /trunk/paso/src/SharedComponents.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2608 - (show annotations)
Tue Aug 18 01:25:18 2009 UTC (10 years, 2 months ago) by jfenwick
File MIME type: text/plain
File size: 3916 byte(s)
Updating Lutz' email

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 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
28 /**************************************************************/
29
30 /* allocates a SharedComponents */
31
32
33 /**************************************************************/
34
35 Paso_SharedComponents* Paso_SharedComponents_alloc(dim_t local_length,
36 dim_t numNeighbors,
37 Paso_MPI_rank* neighbor,
38 index_t* shared,
39 index_t* offsetInShared,
40 index_t m, index_t b,
41 Paso_MPIInfo *mpi_info)
42 {
43 dim_t i,j;
44 register index_t itmp;
45 Paso_SharedComponents* out=NULL;
46 Paso_resetError();
47 out=MEMALLOC(1,Paso_SharedComponents);
48 if (!Paso_checkPtr(out)) {
49 out->local_length=local_length*m;
50 out->mpi_info = Paso_MPIInfo_getReference(mpi_info);
51 out->numNeighbors=numNeighbors;
52 out->neighbor=MEMALLOC(out->numNeighbors,Paso_MPI_rank);
53 if (offsetInShared == NULL) {
54 out->numSharedComponents=0;
55 } else {
56 out->numSharedComponents=offsetInShared[numNeighbors]*m;
57 }
58 out->shared=MEMALLOC(out->numSharedComponents,index_t);
59 out->offsetInShared=MEMALLOC(out->numNeighbors+1,index_t);
60 out->reference_counter=1;
61 if (! (Paso_checkPtr(out->neighbor) ||
62 Paso_checkPtr(out->shared) ||
63 Paso_checkPtr(out->offsetInShared) ) ) {
64
65
66 if ((out->numNeighbors>0) && (offsetInShared!=NULL) ) {
67 #pragma omp parallel
68 {
69 #pragma omp for private(i)
70 for (i=0;i<out->numNeighbors;++i){
71 out->neighbor[i]=neighbor[i];
72 out->offsetInShared[i]=offsetInShared[i]*m;
73 }
74 out->offsetInShared[out->numNeighbors]=offsetInShared[numNeighbors]*m;
75 #pragma omp for private(i,j,itmp)
76 for (i=0;i<offsetInShared[numNeighbors];++i){
77 itmp=m*shared[i]+b;
78 for (j=0;j<m;++j) out->shared[m*i+j]=itmp+j;
79 }
80 }
81 } else {
82 out->offsetInShared[out->numNeighbors]=0;
83 }
84 }
85
86 }
87 if (Paso_noError()) {
88 return out;
89 } else {
90 Paso_SharedComponents_free(out);
91 return NULL;
92 }
93 }
94
95 /* returns a reference to in */
96
97 Paso_SharedComponents* Paso_SharedComponents_getReference(Paso_SharedComponents* in) {
98 if (in!=NULL) {
99 ++(in->reference_counter);
100 }
101 return in;
102 }
103
104 /* deallocates a SharedComponents: */
105
106 void Paso_SharedComponents_free(Paso_SharedComponents* in) {
107 if (in!=NULL) {
108 in->reference_counter--;
109 if (in->reference_counter<=0) {
110 MEMFREE(in->neighbor);
111 MEMFREE(in->shared);
112 MEMFREE(in->offsetInShared);
113 Paso_MPIInfo_free(in->mpi_info);
114 MEMFREE(in);
115 #ifdef Paso_TRACE
116 printf("Paso_SharedComponents_dealloc: system matrix pattern as been deallocated.\n");
117 #endif
118 }
119 }
120 }

  ViewVC Help
Powered by ViewVC 1.1.26