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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (11 years ago) by ksteube
File MIME type: text/plain
File size: 2992 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: PatternPattern */
18
19 /**************************************************************/
20
21 /* Copyrights by ACcESS Australia 2003, 2004, 2005 */
22 /* Author: gross@access.edu.au */
23
24 /**************************************************************/
25
26 #include "Paso.h"
27 #include "Pattern.h"
28 #include "PasoUtil.h"
29
30 /**************************************************************/
31
32 /* creates Pattern */
33
34 Paso_Pattern* Paso_Pattern_getSubpattern(Paso_Pattern* pattern, \
35 int newNumRows, int newNumCols, index_t* row_list,index_t* new_col_index) {
36 index_t index_offset=(pattern->type & PATTERN_FORMAT_OFFSET1 ? 1:0);
37 Paso_Pattern*out=NULL;
38 index_t *ptr=NULL,*index=NULL,k,j,subpattern_row,tmp;
39 dim_t i;
40 Paso_resetError();
41
42 ptr=MEMALLOC(newNumRows+1,index_t);
43 if (! Paso_checkPtr(ptr)) {
44 #pragma omp parallel
45 {
46 #pragma omp for private(i) schedule(static)
47 for (i=0;i<newNumRows+1;++i) ptr[i]=0;
48
49 /* find the number column entries in each row */
50 #pragma omp for private(i,k,j,subpattern_row) schedule(static)
51 for (i=0;i<newNumRows;++i) {
52 j=0;
53 subpattern_row=row_list[i];
54 #pragma ivdep
55 for (k=pattern->ptr[subpattern_row]-index_offset;k<pattern->ptr[subpattern_row+1]-index_offset;++k)
56 if (new_col_index[pattern->index[k]-index_offset]>-1) j++;
57 ptr[i]=j;
58 }
59 }
60 /* accummulate ptr */
61 ptr[newNumRows]=Paso_Util_cumsum(newNumRows,ptr);
62 index=MEMALLOC(ptr[newNumRows],index_t);
63 if (Paso_checkPtr(index)) {
64 MEMFREE(ptr);
65 } else {
66 /* find the number column entries in each row */
67 #pragma omp parallel for private(i,k,j,subpattern_row,tmp) schedule(static)
68 for (i=0;i<newNumRows;++i) {
69 j=ptr[i];
70 subpattern_row=row_list[i];
71 #pragma ivdep
72 for (k=pattern->ptr[subpattern_row]-index_offset;k<pattern->ptr[subpattern_row+1]-index_offset;++k) {
73 tmp=new_col_index[pattern->index[k]-index_offset];
74 if (tmp>-1) {
75 index[j]=tmp;
76 ++j;
77 }
78 }
79 }
80 /* create return value */
81 out=Paso_Pattern_alloc(pattern->type,pattern->input_block_size,pattern->output_block_size,newNumRows,newNumCols,ptr,index);
82 if (! Paso_noError()) {
83 MEMFREE(index);
84 MEMFREE(ptr);
85 }
86 }
87 }
88 return out;
89 }

  ViewVC Help
Powered by ViewVC 1.1.26