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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1384 - (show annotations)
Fri Jan 11 02:29:38 2008 UTC (11 years, 10 months ago) by phornby
Original Path: temp_trunk_copy/paso/src/SharedComponents.c
File MIME type: text/plain
File size: 3830 byte(s)
Make a temp copy of the trunk before checking in the windows changes


1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 /**************************************************************/
17
18 /* Paso: SharedComponents organizes the coupling with in a pattern/matrix */
19 /* across processors */
20
21 /**************************************************************/
22
23 /* Author: gross@access.edu.au */
24
25 /**************************************************************/
26
27 #include "SharedComponents.h"
28
29 /**************************************************************/
30
31 /* allocates a SharedComponents */
32
33
34 /**************************************************************/
35
36 Paso_SharedComponents* Paso_SharedComponents_alloc(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->mpi_info = Paso_MPIInfo_getReference(mpi_info);
50 out->numNeighbors=numNeighbors;
51 out->neighbor=MEMALLOC(out->numNeighbors,Paso_MPI_rank);
52 if (offsetInShared == NULL) {
53 out->numSharedComponents=0;
54 } else {
55 out->numSharedComponents=offsetInShared[numNeighbors]*m;
56 }
57 out->shared=MEMALLOC(out->numSharedComponents,index_t);
58 out->offsetInShared=MEMALLOC(out->numNeighbors+1,index_t);
59 out->reference_counter=1;
60 if (! (Paso_checkPtr(out->neighbor) ||
61 Paso_checkPtr(out->shared) ||
62 Paso_checkPtr(out->offsetInShared) ) ) {
63
64
65 if ((out->numNeighbors>0) && (offsetInShared!=NULL) ) {
66 #pragma omp parallel
67 {
68 #pragma omp for private(i)
69 for (i=0;i<out->numNeighbors;++i){
70 out->neighbor[i]=neighbor[i];
71 out->offsetInShared[i]=offsetInShared[i]*m;
72 }
73 out->offsetInShared[out->numNeighbors]=offsetInShared[numNeighbors]*m;
74 #pragma omp for private(i,j,itmp)
75 for (i=0;i<offsetInShared[numNeighbors];++i){
76 itmp=m*shared[i]+b;
77 for (j=0;j<m;++j) out->shared[m*i+j]=itmp+j;
78 }
79 }
80 } else {
81 out->offsetInShared[out->numNeighbors]=0;
82 }
83 }
84
85 }
86 if (Paso_noError()) {
87 return out;
88 } else {
89 Paso_SharedComponents_free(out);
90 return NULL;
91 }
92 }
93
94 /* returns a reference to in */
95
96 Paso_SharedComponents* Paso_SharedComponents_getReference(Paso_SharedComponents* in) {
97 if (in!=NULL) {
98 ++(in->reference_counter);
99 }
100 return in;
101 }
102
103 /* deallocates a SharedComponents: */
104
105 void Paso_SharedComponents_free(Paso_SharedComponents* in) {
106 if (in!=NULL) {
107 in->reference_counter--;
108 if (in->reference_counter<=0) {
109 MEMFREE(in->neighbor);
110 MEMFREE(in->shared);
111 MEMFREE(in->offsetInShared);
112 Paso_MPIInfo_free(in->mpi_info);
113 MEMFREE(in);
114 #ifdef Paso_TRACE
115 printf("Paso_SharedComponents_dealloc: system matrix pattern as been deallocated.\n");
116 #endif
117 }
118 }
119 }

  ViewVC Help
Powered by ViewVC 1.1.26