/[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 4261 - (hide 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 ksteube 1313
2 jfenwick 3981 /*****************************************************************************
3 ksteube 1811 *
4 jfenwick 4154 * Copyright (c) 2003-2013 by University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 ksteube 1811 *
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 jfenwick 3981 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12     * Development since 2012 by School of Earth Sciences
13     *
14     *****************************************************************************/
15 ksteube 1313
16 ksteube 1811
17 jfenwick 3981 /************************************************************************************/
18 ksteube 1313
19 caltinay 3642 /* Paso: SharedComponents organizes the coupling within a */
20     /* pattern/matrix across processors */
21 ksteube 1313
22 jfenwick 3981 /************************************************************************************/
23 ksteube 1313
24 caltinay 3642 /* Author: Lutz Gross, l.gross@uq.edu.au */
25 ksteube 1313
26 jfenwick 3981 /************************************************************************************/
27 ksteube 1313
28     #include "SharedComponents.h"
29 jfenwick 3259 #include "esysUtils/error.h"
30 ksteube 1313
31 jfenwick 3981 /************************************************************************************/
32 ksteube 1313
33 caltinay 3642 /* allocates SharedComponents */
34 ksteube 1313
35 jfenwick 3981 /************************************************************************************/
36 ksteube 1313
37 gross 1562 Paso_SharedComponents* Paso_SharedComponents_alloc(dim_t local_length,
38     dim_t numNeighbors,
39 jfenwick 3259 Esys_MPI_rank* neighbor,
40 ksteube 1313 index_t* shared,
41     index_t* offsetInShared,
42     index_t m, index_t b,
43 jfenwick 3259 Esys_MPIInfo *mpi_info)
44 ksteube 1313 {
45     dim_t i,j;
46     register index_t itmp;
47     Paso_SharedComponents* out=NULL;
48 jfenwick 3259 Esys_resetError();
49 ksteube 1313 out=MEMALLOC(1,Paso_SharedComponents);
50 jfenwick 3259 if (!Esys_checkPtr(out)) {
51 gross 1562 out->local_length=local_length*m;
52 jfenwick 3259 out->mpi_info = Esys_MPIInfo_getReference(mpi_info);
53 ksteube 1313 out->numNeighbors=numNeighbors;
54 jfenwick 3259 out->neighbor=MEMALLOC(out->numNeighbors,Esys_MPI_rank);
55 ksteube 1313 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 jfenwick 3259 if (! (Esys_checkPtr(out->neighbor) ||
64     Esys_checkPtr(out->shared) ||
65     Esys_checkPtr(out->offsetInShared) ) ) {
66 ksteube 1313
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 jfenwick 3259 if (Esys_noError()) {
90 ksteube 1313 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 caltinay 3642 /* deallocates SharedComponents */
107 ksteube 1313
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 jfenwick 3259 Esys_MPIInfo_free(in->mpi_info);
116 ksteube 1313 MEMFREE(in);
117     #ifdef Paso_TRACE
118 caltinay 3642 printf("Paso_SharedComponents_dealloc: system matrix pattern has been deallocated.\n");
119 ksteube 1313 #endif
120     }
121     }
122     }
123 caltinay 3642

  ViewVC Help
Powered by ViewVC 1.1.26