1 |
/* $Id$ */ |
2 |
|
3 |
/* |
4 |
******************************************************************************** |
5 |
* Copyright 2006 by ACcESS MNRF * |
6 |
* * |
7 |
* http://www.access.edu.au * |
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 |
/* Paso: SystemMatrixPatternPattern */ |
17 |
|
18 |
/**************************************************************/ |
19 |
|
20 |
/* Copyrights by ACcESS Australia 2003, 2004,2005 */ |
21 |
/* Author: gross@access.edu.au */ |
22 |
|
23 |
/**************************************************************/ |
24 |
|
25 |
#include "Paso.h" |
26 |
#include "SystemMatrixPattern.h" |
27 |
|
28 |
/**************************************************************/ |
29 |
|
30 |
/* allocates a SystemMatrixPattern */ |
31 |
|
32 |
Paso_SystemMatrixPattern* Paso_SystemMatrixPattern_alloc(int type, int n_ptr, index_t* ptr,index_t* index) { |
33 |
Paso_SystemMatrixPattern*out; |
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; |
37 |
Paso_resetError(); |
38 |
|
39 |
if (type & PATTERN_FORMAT_SYM) { |
40 |
Paso_setError(TYPE_ERROR,"symmetric matrix pattern is not supported yet"); |
41 |
return NULL; |
42 |
} |
43 |
#pragma omp parallel private(loc_min_index,loc_max_index,i) |
44 |
{ |
45 |
loc_min_index=index_offset; |
46 |
loc_max_index=index_offset-1; |
47 |
if (type & PATTERN_FORMAT_OFFSET1) { |
48 |
#pragma omp for schedule(static) |
49 |
for (i=0;i<n_ptr;++i) { |
50 |
if (ptr[i]<ptr[i+1]) { |
51 |
#ifdef USE_QSORTG |
52 |
qsortG(&(index[ptr[i]-1]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex); |
53 |
#else |
54 |
qsort(&(index[ptr[i]-1]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex); |
55 |
#endif |
56 |
loc_min_index=MIN(loc_min_index,index[ptr[i]-1]); |
57 |
loc_max_index=MAX(loc_max_index,index[ptr[i+1]-2]); |
58 |
} |
59 |
} |
60 |
} else { |
61 |
#pragma omp for schedule(static) |
62 |
for (i=0;i<n_ptr;++i) { |
63 |
if (ptr[i]<ptr[i+1]) { |
64 |
#ifdef USE_QSORTG |
65 |
qsortG(&(index[ptr[i]]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex); |
66 |
#else |
67 |
qsort(&(index[ptr[i]]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex); |
68 |
#endif |
69 |
loc_min_index=MIN(loc_min_index,index[ptr[i]]); |
70 |
loc_max_index=MAX(loc_max_index,index[ptr[i+1]-1]); |
71 |
} |
72 |
} |
73 |
} |
74 |
#pragma omp critical |
75 |
{ |
76 |
min_index=MIN(loc_min_index,min_index); |
77 |
max_index=MAX(loc_max_index,max_index); |
78 |
} |
79 |
} |
80 |
if (min_index<index_offset) { |
81 |
Paso_setError(TYPE_ERROR,"Matrix pattern index out of range."); |
82 |
return NULL; |
83 |
} |
84 |
|
85 |
out=MEMALLOC(1,Paso_SystemMatrixPattern); |
86 |
if (Paso_checkPtr(out)) return NULL; |
87 |
out->n_ptr=n_ptr; |
88 |
out->n_index=max_index-index_offset+1; |
89 |
out->ptr=ptr; |
90 |
out->index=index; |
91 |
out->len=out->ptr[out->n_ptr]-index_offset; |
92 |
out->reference_counter=1; |
93 |
out->type=type; |
94 |
#ifdef Paso_TRACE |
95 |
printf("Paso_SystemMatrixPattern_dealloc: system matrix pattern as been allocated.\n"); |
96 |
#endif |
97 |
return out; |
98 |
} |
99 |
|
100 |
/* returns a reference to in */ |
101 |
|
102 |
Paso_SystemMatrixPattern* Paso_SystemMatrixPattern_reference(Paso_SystemMatrixPattern* in) { |
103 |
if (in!=NULL) { |
104 |
++(in->reference_counter); |
105 |
} |
106 |
return in; |
107 |
} |
108 |
|
109 |
/* deallocates a SystemMatrixPattern: */ |
110 |
|
111 |
void Paso_SystemMatrixPattern_dealloc(Paso_SystemMatrixPattern* in) { |
112 |
if (in!=NULL) { |
113 |
in->reference_counter--; |
114 |
if (in->reference_counter<=0) { |
115 |
MEMFREE(in->ptr); |
116 |
MEMFREE(in->index); |
117 |
MEMFREE(in); |
118 |
#ifdef Paso_TRACE |
119 |
printf("Paso_SystemMatrixPattern_dealloc: system matrix pattern as been deallocated.\n"); |
120 |
#endif |
121 |
} |
122 |
} |
123 |
} |
124 |
/* *************************************************************/ |
125 |
|
126 |
/* some routines which help to get the matrix pattern from elements: */ |
127 |
|
128 |
/* this routine is used by qsort called in Paso_SystemMatrixPattern_alloc */ |
129 |
|
130 |
int Paso_comparIndex(const void *index1,const void *index2){ |
131 |
index_t Iindex1,Iindex2; |
132 |
Iindex1=*(index_t*)index1; |
133 |
Iindex2=*(index_t*)index2; |
134 |
if (Iindex1<Iindex2) { |
135 |
return -1; |
136 |
} else { |
137 |
if (Iindex1>Iindex2) { |
138 |
return 1; |
139 |
} else { |
140 |
return 0; |
141 |
} |
142 |
} |
143 |
} |
144 |
/* |
145 |
* $Log$ |
146 |
* Revision 1.2 2005/09/15 03:44:38 jgs |
147 |
* Merge of development branch dev-02 back to main trunk on 2005-09-15 |
148 |
* |
149 |
* Revision 1.1.2.1 2005/09/05 06:29:47 gross |
150 |
* These files have been extracted from finley to define a stand alone libray for iterative |
151 |
* linear solvers on the ALTIX. main entry through Paso_solve. this version compiles but |
152 |
* has not been tested yet. |
153 |
* |
154 |
* |
155 |
*/ |