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