/[escript]/trunk/esys2/finley/src/finleyC/SystemPattern.c
ViewVC logotype

Contents of /trunk/esys2/finley/src/finleyC/SystemPattern.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 115 - (show annotations)
Fri Mar 4 07:12:47 2005 UTC (14 years, 1 month ago) by jgs
File MIME type: text/plain
File size: 3421 byte(s)
*** empty log message ***

1 /* $Id$ */
2
3 /**************************************************************/
4
5 /* Finley: SystemMatrixPatternPattern */
6
7 /**************************************************************/
8
9 /* Copyrights by ACcESS Australia 2003, 2004 */
10 /* Author: gross@access.edu.au */
11
12 /**************************************************************/
13
14 #include "Finley.h"
15 #include "Common.h"
16 #include "SystemPattern.h"
17
18 /**************************************************************/
19
20 /* allocates a SystemMatrixPattern */
21
22 Finley_SystemMatrixPattern* Finley_SystemMatrixPattern_alloc(int n_ptr, maybelong* ptr,maybelong* index) {
23 Finley_SystemMatrixPattern*out;
24 maybelong loc_min_index,loc_max_index,min_index=INDEX_OFFSET,max_index=INDEX_OFFSET-1;
25 maybelong i,k;
26 Finley_ErrorCode=NO_ERROR;
27
28
29 #pragma omp parallel private(loc_min_index,loc_max_index,i,k)
30 {
31 loc_min_index=INDEX_OFFSET;
32 loc_max_index=INDEX_OFFSET-1;
33 #if PTR_OFFSET>0
34 #pragma omp for schedule(static)
35 for (i=0;i<n_ptr+1;++i) ptr[i]+=PTR_OFFSET;
36 #endif
37 #if INDEX_OFFSET>0
38 #pragma omp for schedule(static)
39 for (i=0;i<n_ptr;++i)
40 for (k=ptr[i];k<ptr[i+1];++k) index[k]+=INDEX_OFFSET;
41 #endif
42
43 #pragma omp for schedule(static)
44 for (i=0;i<n_ptr;++i) {
45 if (ptr[i]<ptr[i+1]) {
46 qsort(&(index[ptr[i]-PTR_OFFSET]),(int)(ptr[i+1]-ptr[i]),sizeof(maybelong),Finley_comparIndex);
47 loc_min_index=MIN(loc_min_index,index[ptr[i]]);
48 loc_max_index=MAX(loc_max_index,index[ptr[i+1]-1]);
49 }
50 }
51 #pragma omp critical
52 {
53 min_index=MIN(loc_min_index,min_index);
54 max_index=MAX(loc_max_index,max_index);
55 }
56 }
57 if (min_index<INDEX_OFFSET) {
58 Finley_ErrorCode=TYPE_ERROR;
59 sprintf(Finley_ErrorMsg,"Matrix pattern index out of range.");
60 return NULL;
61 }
62
63 out=MEMALLOC(1,Finley_SystemMatrixPattern);
64 if (Finley_checkPtr(out)) return NULL;
65 out->n_ptr=n_ptr;
66 out->n_index=max_index+1-INDEX_OFFSET;
67 out->ptr=ptr;
68 out->index=index;
69 out->len=out->ptr[out->n_ptr];
70 out->reference_counter=1;
71 #ifdef Finley_TRACE
72 printf("Finley_SystemMatrixPattern_dealloc: system matrix pattern as been allocated.\n");
73 #endif
74 return out;
75 }
76
77 /* returns a reference to in */
78
79 Finley_SystemMatrixPattern* Finley_SystemMatrixPattern_reference(Finley_SystemMatrixPattern* in) {
80 if (in!=NULL) ++in->reference_counter;
81 return in;
82 }
83
84 /* deallocates a SystemMatrixPattern: */
85
86 void Finley_SystemMatrixPattern_dealloc(Finley_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 Finley_TRACE
94 printf("Finley_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 Finley_SystemMatrixPattern_alloc */
104
105 int Finley_comparIndex(const void *index1,const void *index2){
106 maybelong Iindex1,Iindex2;
107 Iindex1=*(maybelong*)index1;
108 Iindex2=*(maybelong*)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 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26