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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (11 years, 4 months ago) by ksteube
File MIME type: text/plain
File size: 4940 byte(s)
Copyright updated in all files

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 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: Pattern */
18
19 /**************************************************************/
20
21 /* Author: gross@access.edu.au */
22
23 /**************************************************************/
24
25 #include "Paso.h"
26 #include "Pattern.h"
27
28 /**************************************************************/
29
30 /* allocates a Pattern */
31
32 Paso_Pattern* Paso_Pattern_alloc(int type, dim_t input_block_size, dim_t output_block_size, dim_t numOutput, dim_t numInput, index_t* ptr, index_t* index) {
33 Paso_Pattern*out=NULL;
34 index_t index_offset=(type & PATTERN_FORMAT_OFFSET1 ? 1:0);
35 index_t loc_min_index,loc_max_index,min_index=index_offset,max_index=index_offset-1;
36 dim_t i, sum=0;
37 Paso_resetError();
38
39 if (type & PATTERN_FORMAT_SYM) {
40 Paso_setError(TYPE_ERROR,"Paso_Pattern_alloc: symmetric matrix pattern is not supported yet");
41 return NULL;
42 }
43 if (ptr!=NULL && index != NULL) {
44 #pragma omp parallel private(loc_min_index,loc_max_index,i)
45 {
46 loc_min_index=index_offset;
47 loc_max_index=index_offset-1;
48 if (type & PATTERN_FORMAT_OFFSET1) {
49 #pragma omp for schedule(static)
50 for (i=0;i<numOutput;++i) {
51 if (ptr[i]<ptr[i+1]) {
52 #ifdef USE_QSORTG
53 qsortG(&(index[ptr[i]-1]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex);
54 #else
55 qsort(&(index[ptr[i]-1]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex);
56 #endif
57 loc_min_index=MIN(loc_min_index,index[ptr[i]-1]);
58 loc_max_index=MAX(loc_max_index,index[ptr[i+1]-2]);
59 }
60 }
61 } else {
62 #pragma omp for schedule(static)
63 for (i=0;i<numOutput;++i) {
64 if (ptr[i]<ptr[i+1]) {
65 #ifdef USE_QSORTG
66 qsortG(&(index[ptr[i]]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex);
67 #else
68 qsort(&(index[ptr[i]]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex);
69 #endif
70 loc_min_index=MIN(loc_min_index,index[ptr[i]]);
71 loc_max_index=MAX(loc_max_index,index[ptr[i+1]-1]);
72 }
73 }
74 }
75 #pragma omp critical
76 {
77 min_index=MIN(loc_min_index,min_index);
78 max_index=MAX(loc_max_index,max_index);
79 }
80 }
81 if ( (min_index<index_offset) || (max_index>=numInput+index_offset) ) {
82 Paso_setError(TYPE_ERROR,"Paso_Pattern_alloc: Pattern index out of range.");
83 return NULL;
84 }
85 }
86 out=MEMALLOC(1,Paso_Pattern);
87 if (! Paso_checkPtr(out)) {
88 out->type=type;
89 out->reference_counter=1;
90 out->numOutput=numOutput;
91 out->numInput=numInput;
92 out->ptr=ptr;
93 out->index=index;
94 out->input_block_size=input_block_size;
95 out->output_block_size=output_block_size;
96 out->block_size=out->input_block_size * out->output_block_size;
97 if (out->ptr == NULL) {
98 out->len=0;
99 } else {
100 out->len=out->ptr[out->numOutput] - index_offset;
101 }
102 }
103 #ifdef Paso_TRACE
104 printf("Paso_Pattern_alloc: system matrix pattern as been allocated.\n");
105 #endif
106 return out;
107 }
108
109 /* returns a reference to in */
110
111 Paso_Pattern* Paso_Pattern_getReference(Paso_Pattern* in) {
112 if (in!=NULL) {
113 ++(in->reference_counter);
114 }
115 return in;
116 }
117
118 /* deallocates a Pattern: */
119
120 void Paso_Pattern_free(Paso_Pattern* in) {
121 if (in!=NULL) {
122 in->reference_counter--;
123 if (in->reference_counter<=0) {
124 MEMFREE(in->ptr);
125 MEMFREE(in->index);
126 MEMFREE(in);
127 #ifdef Paso_TRACE
128 printf("Paso_Pattern_free: pattern as been deallocated.\n");
129 #endif
130 }
131 }
132 }
133 /* *************************************************************/
134
135 /* some routines which help to get the matrix pattern from elements: */
136
137 /* this routine is used by qsort called in Paso_Pattern_alloc */
138
139 int Paso_comparIndex(const void *index1,const void *index2){
140 index_t Iindex1,Iindex2;
141 Iindex1=*(index_t*)index1;
142 Iindex2=*(index_t*)index2;
143 if (Iindex1<Iindex2) {
144 return -1;
145 } else {
146 if (Iindex1>Iindex2) {
147 return 1;
148 } else {
149 return 0;
150 }
151 }
152 }
153
154 bool_t Paso_Pattern_isEmpty(Paso_Pattern* in) {
155 if (in != NULL) {
156 if ((in->ptr != NULL) && (in->index != NULL)) return FALSE;
157 }
158 return TRUE;
159 }

  ViewVC Help
Powered by ViewVC 1.1.26