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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3259 - (hide annotations)
Mon Oct 11 01:48:14 2010 UTC (8 years, 7 months ago) by jfenwick
File MIME type: text/plain
File size: 3945 byte(s)
Merging dudley and scons updates from branches

1 ksteube 1313
2     /*******************************************************
3 ksteube 1811 *
4 jfenwick 2881 * Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1811 * 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 ksteube 1313
14 ksteube 1811
15 ksteube 1313 /**************************************************************/
16    
17     /* Paso: SharedComponents organizes the coupling with in a pattern/matrix */
18     /* across processors */
19    
20     /**************************************************************/
21    
22 jfenwick 2608 /* Author: Lutz Gross, l.gross@uq.edu.au */
23 ksteube 1313
24     /**************************************************************/
25    
26     #include "SharedComponents.h"
27 jfenwick 3259 #include "esysUtils/error.h"
28 ksteube 1313
29     /**************************************************************/
30    
31     /* allocates a SharedComponents */
32    
33    
34     /**************************************************************/
35    
36 gross 1562 Paso_SharedComponents* Paso_SharedComponents_alloc(dim_t local_length,
37     dim_t numNeighbors,
38 jfenwick 3259 Esys_MPI_rank* neighbor,
39 ksteube 1313 index_t* shared,
40     index_t* offsetInShared,
41     index_t m, index_t b,
42 jfenwick 3259 Esys_MPIInfo *mpi_info)
43 ksteube 1313 {
44     dim_t i,j;
45     register index_t itmp;
46     Paso_SharedComponents* out=NULL;
47 jfenwick 3259 Esys_resetError();
48 ksteube 1313 out=MEMALLOC(1,Paso_SharedComponents);
49 jfenwick 3259 if (!Esys_checkPtr(out)) {
50 gross 1562 out->local_length=local_length*m;
51 jfenwick 3259 out->mpi_info = Esys_MPIInfo_getReference(mpi_info);
52 ksteube 1313 out->numNeighbors=numNeighbors;
53 jfenwick 3259 out->neighbor=MEMALLOC(out->numNeighbors,Esys_MPI_rank);
54 ksteube 1313 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 jfenwick 3259 if (! (Esys_checkPtr(out->neighbor) ||
63     Esys_checkPtr(out->shared) ||
64     Esys_checkPtr(out->offsetInShared) ) ) {
65 ksteube 1313
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 jfenwick 3259 if (Esys_noError()) {
89 ksteube 1313 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 jfenwick 3259 Esys_MPIInfo_free(in->mpi_info);
115 ksteube 1313 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