/[escript]/branches/doubleplusgood/paso/src/Pattern_getSubpattern.cpp
ViewVC logotype

Contents of /branches/doubleplusgood/paso/src/Pattern_getSubpattern.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4261 - (show annotations)
Wed Feb 27 06:09:33 2013 UTC (6 years, 1 month ago) by jfenwick
File size: 3154 byte(s)
Initial all c++ build.
But ... there are now reinterpret_cast<>'s
1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16
17 /************************************************************************************/
18
19 /* Paso: Pattern */
20
21 /************************************************************************************/
22
23 /* Copyrights by ACcESS Australia 2003, 2004, 2005 */
24 /* Author: Lutz Gross, l.gross@uq.edu.au */
25
26 /************************************************************************************/
27
28 #include "Paso.h"
29 #include "Pattern.h"
30 #include "PasoUtil.h"
31
32 /************************************************************************************/
33
34 /* creates Pattern */
35
36 Paso_Pattern* Paso_Pattern_getSubpattern(Paso_Pattern* pattern, \
37 int newNumRows, int newNumCols, index_t* row_list,index_t* new_col_index) {
38 index_t index_offset=(pattern->type & MATRIX_FORMAT_OFFSET1 ? 1:0);
39 Paso_Pattern*out=NULL;
40 index_t *ptr=NULL,*index=NULL,k,j,subpattern_row,tmp;
41 dim_t i;
42 Esys_resetError();
43
44 ptr=MEMALLOC(newNumRows+1,index_t);
45 if (! Esys_checkPtr(ptr)) {
46 #pragma omp parallel
47 {
48 #pragma omp for private(i) schedule(static)
49 for (i=0;i<newNumRows+1;++i) ptr[i]=0;
50
51 /* find the number of column entries in each row */
52 #pragma omp for private(i,k,j,subpattern_row) schedule(static)
53 for (i=0;i<newNumRows;++i) {
54 j=0;
55 subpattern_row=row_list[i];
56 #pragma ivdep
57 for (k=pattern->ptr[subpattern_row]-index_offset;k<pattern->ptr[subpattern_row+1]-index_offset;++k)
58 if (new_col_index[pattern->index[k]-index_offset]>-1) j++;
59 ptr[i]=j;
60 }
61 }
62 /* accumulate ptr */
63 ptr[newNumRows]=Paso_Util_cumsum(newNumRows,ptr);
64 index=MEMALLOC(ptr[newNumRows],index_t);
65 if (Esys_checkPtr(index)) {
66 MEMFREE(ptr);
67 } else {
68 /* find the number of column entries in each row */
69 #pragma omp parallel for private(i,k,j,subpattern_row,tmp) schedule(static)
70 for (i=0;i<newNumRows;++i) {
71 j=ptr[i];
72 subpattern_row=row_list[i];
73 #pragma ivdep
74 for (k=pattern->ptr[subpattern_row]-index_offset;k<pattern->ptr[subpattern_row+1]-index_offset;++k) {
75 tmp=new_col_index[pattern->index[k]-index_offset];
76 if (tmp>-1) {
77 index[j]=tmp;
78 ++j;
79 }
80 }
81 }
82 /* create return value */
83 out=Paso_Pattern_alloc(pattern->type,newNumRows,newNumCols,ptr,index);
84 if (! Esys_noError()) {
85 MEMFREE(index);
86 MEMFREE(ptr);
87 }
88 }
89 }
90 return out;
91 }
92

  ViewVC Help
Powered by ViewVC 1.1.26