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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2608 - (show annotations)
Tue Aug 18 01:25:18 2009 UTC (10 years, 1 month ago) by jfenwick
File MIME type: text/plain
File size: 3841 byte(s)
Updating Lutz' email

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 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: Pattern_unrollBlocks */
18
19 /**************************************************************/
20
21 /* Author: Lutz Gross, l.gross@uq.edu.au */
22
23 /**************************************************************/
24
25 #include "Paso.h"
26 #include "Pattern.h"
27
28 /**************************************************************/
29
30 /* creates Pattern */
31
32 Paso_Pattern* Paso_Pattern_unrollBlocks(Paso_Pattern* pattern, \
33 int type, dim_t output_block_size,dim_t input_block_size) {
34 Paso_Pattern*out=NULL;
35 index_t *ptr=NULL,*index=NULL,iPtr;
36 dim_t i,j,k, block_size, new_len, new_numOutput, new_numInput;
37 index_t index_offset_in=(pattern->type & PATTERN_FORMAT_OFFSET1 ? 1:0);
38 index_t index_offset_out=(type & PATTERN_FORMAT_OFFSET1 ? 1:0);
39
40 Paso_resetError();
41 if ((pattern->type & PATTERN_FORMAT_SYM) != (type & PATTERN_FORMAT_SYM)) {
42 Paso_setError(TYPE_ERROR,"Paso_Pattern_unrollBlocks: conversion between symmetric and non-symmetric is not implemented yet");
43 return NULL;
44 }
45 if ( ( output_block_size == 1 ) && (input_block_size == 1) && ((pattern->type & PATTERN_FORMAT_OFFSET1) == (type & PATTERN_FORMAT_OFFSET1) ) ) {
46 out = Paso_Pattern_getReference(pattern);
47 } else {
48 block_size=output_block_size*input_block_size;
49 new_len=(pattern->len)*block_size;
50 new_numOutput=(pattern->numOutput)*output_block_size;
51 new_numInput=(pattern->numInput)*input_block_size;
52
53 ptr=MEMALLOC(new_numOutput+1,index_t);
54 index=MEMALLOC(new_len,index_t);
55 if (! ( Paso_checkPtr(ptr) || Paso_checkPtr(index) ) ) {
56 #pragma omp parallel
57 {
58 #pragma omp for private(i) schedule(static)
59 for (i=0;i<new_numOutput+1;++i) ptr[i]=index_offset_out;
60
61 #pragma omp single
62 ptr[new_numOutput]=new_len+index_offset_out;
63
64 #pragma omp for private(i,k) schedule(static)
65 for (i=0;i<pattern->numOutput;++i) {
66 for (k=0;k<output_block_size;++k) {
67 ptr[i*output_block_size+k]=(pattern->ptr[i]-index_offset_in)*block_size+
68 (pattern->ptr[i+1]-pattern->ptr[i])*input_block_size*k+index_offset_out;
69 }
70 }
71
72 #pragma omp for private(i,iPtr) schedule(static)
73 for (i=0;i<new_numOutput;++i) {
74 #pragma ivdep
75 for (iPtr=ptr[i]-index_offset_out;iPtr<ptr[i+1]-index_offset_out;++iPtr) index[iPtr]=index_offset_out;
76 }
77
78 #pragma omp for private(i,j,iPtr,k) schedule(static)
79 for (i=0;i<pattern->numOutput;++i) {
80 for (iPtr=pattern->ptr[i]-index_offset_in;iPtr<pattern->ptr[i+1]-index_offset_in;++iPtr) {
81 for (k=0;k<output_block_size;++k) {
82 #pragma ivdep
83 for (j=0;j<input_block_size;++j) {
84 index[ptr[i*output_block_size+k]-index_offset_out+(iPtr-(pattern->ptr[i]-index_offset_in))*input_block_size+j]=(pattern->index[iPtr]-index_offset_in)*input_block_size+j+index_offset_out;
85 }
86 }
87 }
88 }
89 }
90 out=Paso_Pattern_alloc(type,new_numOutput,new_numInput,ptr,index);
91 }
92 if (! Paso_noError()) {
93 MEMFREE(index);
94 MEMFREE(ptr);
95 }
96 }
97 return out;
98 }

  ViewVC Help
Powered by ViewVC 1.1.26