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

Contents of /trunk-mpi-branch/paso/src/Pattern.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1284 - (show annotations)
Mon Sep 3 04:47:52 2007 UTC (11 years, 7 months ago) by ksteube
File MIME type: text/plain
File size: 4974 byte(s)
Pattern length was incorrect
Adjusted #pragma ivdep

1 /* $Id$ */
2
3 /*
4 ********************************************************************************
5 * Copyright 2006, 2007 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: Pattern */
17
18 /**************************************************************/
19
20 /* Author: gross@access.edu.au */
21
22 /**************************************************************/
23
24 #include "Paso.h"
25 #include "Pattern.h"
26
27 /**************************************************************/
28
29 /* allocates a Pattern */
30
31 Paso_Pattern* Paso_Pattern_alloc(int type, dim_t numOutput, index_t* ptr, index_t* index) {
32 Paso_Pattern*out=NULL;
33 index_t index_offset=(type & PATTERN_FORMAT_OFFSET1 ? 1:0);
34 index_t loc_min_index,loc_max_index,min_index=index_offset,max_index=index_offset-1;
35 dim_t i, sum=0;
36 Paso_resetError();
37
38 if (type & PATTERN_FORMAT_SYM) {
39 Paso_setError(TYPE_ERROR,"Paso_Pattern_alloc: symmetric matrix pattern is not supported yet");
40 return NULL;
41 }
42 if (ptr!=NULL && index != NULL) {
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<numOutput;++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<numOutput;++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,"Paso_Pattern_alloc: lower Pattern index out of range.");
82 return NULL;
83 }
84 }
85 out=MEMALLOC(1,Paso_Pattern);
86 if (! Paso_checkPtr(out)) {
87 out->type=type;
88 out->reference_counter=1;
89 out->numOutput=numOutput;
90 out->ptr=ptr;
91 out->index=index;
92 if (out->ptr == NULL) {
93 out->len=0;
94 out->numInput=0;
95 } else {
96 out->len=out->ptr[out->numOutput] - index_offset;
97 out->numInput=max_index+1-index_offset;
98 }
99 }
100 #ifdef Paso_TRACE
101 printf("Paso_Pattern_alloc: system matrix pattern as been allocated.\n");
102 #endif
103 return out;
104 }
105
106 /* returns a reference to in */
107
108 Paso_Pattern* Paso_Pattern_getReference(Paso_Pattern* in) {
109 if (in!=NULL) {
110 ++(in->reference_counter);
111 }
112 return in;
113 }
114
115 /* deallocates a Pattern: */
116
117 void Paso_Pattern_free(Paso_Pattern* in) {
118 if (in!=NULL) {
119 in->reference_counter--;
120 if (in->reference_counter<=0) {
121 MEMFREE(in->ptr);
122 MEMFREE(in->index);
123 MEMFREE(in);
124 #ifdef Paso_TRACE
125 printf("Paso_Pattern_free: pattern as been deallocated.\n");
126 #endif
127 }
128 }
129 }
130 /* *************************************************************/
131
132 /* some routines which help to get the matrix pattern from elements: */
133
134 /* this routine is used by qsort called in Paso_Pattern_alloc */
135
136 int Paso_comparIndex(const void *index1,const void *index2){
137 index_t Iindex1,Iindex2;
138 Iindex1=*(index_t*)index1;
139 Iindex2=*(index_t*)index2;
140 if (Iindex1<Iindex2) {
141 return -1;
142 } else {
143 if (Iindex1>Iindex2) {
144 return 1;
145 } else {
146 return 0;
147 }
148 }
149 }
150
151 bool_t Paso_Pattern_isEmpty(Paso_Pattern* in) {
152 if (in != NULL) {
153 if ((in->ptr != NULL) && (in->index != NULL)) return FALSE;
154 }
155 return TRUE;
156 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26