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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3911 - (hide annotations)
Thu Jun 14 01:01:03 2012 UTC (6 years, 10 months ago) by jfenwick
Original Path: trunk/paso/src/SharedComponents.c
File MIME type: text/plain
File size: 3943 byte(s)
Copyright changes
1 ksteube 1313
2     /*******************************************************
3 ksteube 1811 *
4 jfenwick 3911 * Copyright (c) 2003-2012 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 caltinay 3642 /* Paso: SharedComponents organizes the coupling within a */
18     /* pattern/matrix across processors */
19 ksteube 1313
20     /**************************************************************/
21    
22 caltinay 3642 /* 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 caltinay 3642 /* allocates SharedComponents */
32 ksteube 1313
33     /**************************************************************/
34    
35 gross 1562 Paso_SharedComponents* Paso_SharedComponents_alloc(dim_t local_length,
36     dim_t numNeighbors,
37 jfenwick 3259 Esys_MPI_rank* neighbor,
38 ksteube 1313 index_t* shared,
39     index_t* offsetInShared,
40     index_t m, index_t b,
41 jfenwick 3259 Esys_MPIInfo *mpi_info)
42 ksteube 1313 {
43     dim_t i,j;
44     register index_t itmp;
45     Paso_SharedComponents* out=NULL;
46 jfenwick 3259 Esys_resetError();
47 ksteube 1313 out=MEMALLOC(1,Paso_SharedComponents);
48 jfenwick 3259 if (!Esys_checkPtr(out)) {
49 gross 1562 out->local_length=local_length*m;
50 jfenwick 3259 out->mpi_info = Esys_MPIInfo_getReference(mpi_info);
51 ksteube 1313 out->numNeighbors=numNeighbors;
52 jfenwick 3259 out->neighbor=MEMALLOC(out->numNeighbors,Esys_MPI_rank);
53 ksteube 1313 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 jfenwick 3259 if (! (Esys_checkPtr(out->neighbor) ||
62     Esys_checkPtr(out->shared) ||
63     Esys_checkPtr(out->offsetInShared) ) ) {
64 ksteube 1313
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 jfenwick 3259 if (Esys_noError()) {
88 ksteube 1313 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 caltinay 3642 /* deallocates SharedComponents */
105 ksteube 1313
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 jfenwick 3259 Esys_MPIInfo_free(in->mpi_info);
114 ksteube 1313 MEMFREE(in);
115     #ifdef Paso_TRACE
116 caltinay 3642 printf("Paso_SharedComponents_dealloc: system matrix pattern has been deallocated.\n");
117 ksteube 1313 #endif
118     }
119     }
120     }
121 caltinay 3642

  ViewVC Help
Powered by ViewVC 1.1.26