MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RTOp_apply_op_serial.c
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
6 // Copyright (2003) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 /* ////////////////////////////////////////////////////////////// */
45 /* RTOp_apply_op_serial.c */
46 
47 #include "RTOp_apply_op_serial.h"
48 
49 #include <stdlib.h>
50 
52  RTOp_index_type full_dim
53  ,const int num_vecs, const RTOp_value_type* vec_ptrs[], const ptrdiff_t vec_strides[]
54  ,const int num_targ_vecs, RTOp_value_type* targ_vec_ptrs[], const ptrdiff_t targ_vec_strides[]
55  ,const RTOp_index_type first_ele_in, const RTOp_index_type sub_dim_in, const RTOp_index_type global_offset_in
56  ,const struct RTOp_RTOp* op
57  ,RTOp_ReductTarget reduct_obj
58  )
59 {
60  int err = 0;
62  struct RTOp_SubVector *sub_vecs = NULL;
63  struct RTOp_MutableSubVector *targ_sub_vecs = NULL;
64  int k;
65  /* Sort out the input and get the number of vector elements to operator over */
66 #ifdef RTOp_DEBUG
67  assert( num_vecs || num_targ_vecs );
68  if(num_vecs)
69  assert( vec_ptrs != NULL );
70  if(num_targ_vecs)
71  assert( targ_vec_ptrs != NULL );
72  assert( 0 <= sub_dim_in && sub_dim_in <= full_dim );
73 #endif
74  sub_dim = sub_dim_in ? sub_dim_in : full_dim - (first_ele_in - 1); /* Dimension of logical vectors */
75  /* Create the sub-vector data structures */
76  if(num_vecs) {
77  sub_vecs = malloc( sizeof(struct RTOp_SubVector) * num_vecs );
78  for( k = 0; k < num_vecs; ++k ) {
79 #ifdef RTOp_DEBUG
80  assert( vec_ptrs[k] != NULL );
81 #endif
83  global_offset_in
84  ,sub_dim
85  ,vec_ptrs[k] + (first_ele_in -1) * vec_strides[k]
86  ,vec_strides[k]
87  ,&sub_vecs[k]
88  );
89  }
90  }
91  if(num_targ_vecs) {
92  targ_sub_vecs = malloc( sizeof(struct RTOp_MutableSubVector) * num_targ_vecs );
93  for( k = 0; k < num_targ_vecs; ++k ) {
94 #ifdef RTOp_DEBUG
95  assert( targ_vec_ptrs[k] != NULL );
96 #endif
98  global_offset_in
99  ,sub_dim
100  ,targ_vec_ptrs[k] + (first_ele_in -1) * targ_vec_strides[k]
101  ,targ_vec_strides[k]
102  ,&targ_sub_vecs[k]
103  );
104  }
105  }
106  /* Apply the reduction/transformation operator in one chunk */
107  err = RTOp_apply_op( op, num_vecs, sub_vecs, num_targ_vecs, targ_sub_vecs, reduct_obj );
108  /* Free the sub-vector data structures */
109  if( sub_vecs ) free( sub_vecs );
110  if( targ_sub_vecs ) free( targ_sub_vecs );
111 
112  return err; /* This could be an error code! */
113 }
double RTOp_value_type
Definition: RTOp.h:69
void * RTOp_ReductTarget
Definition: RTOp.h:191
void RTOp_mutable_sub_vector(RTOp_index_type global_offset, RTOp_index_type sub_dim, RTOp_value_type values[], ptrdiff_t values_stride, struct RTOp_MutableSubVector *sub_vec)
Definition: RTOp.c:77
void RTOp_sub_vector(RTOp_index_type global_offset, RTOp_index_type sub_dim, const RTOp_value_type values[], ptrdiff_t values_stride, struct RTOp_SubVector *sub_vec)
Definition: RTOp.c:52
int RTOp_apply_op(const struct RTOp_RTOp *op, const int num_vecs, const struct RTOp_SubVector sub_vecs[], const int num_targ_vecs, const struct RTOp_MutableSubVector targ_sub_vecs[], RTOp_ReductTarget reduct_obj)
Definition: RTOp.c:357
RTOp_index_type sub_dim
Definition: RTOp.h:334
int RTOp_apply_op_serial(RTOp_index_type full_dim, const int num_vecs, const RTOp_value_type *vec_ptrs[], const ptrdiff_t vec_strides[], const int num_targ_vecs, RTOp_value_type *targ_vec_ptrs[], const ptrdiff_t targ_vec_strides[], const RTOp_index_type first_ele_in, const RTOp_index_type sub_dim_in, const RTOp_index_type global_offset_in, const struct RTOp_RTOp *op, RTOp_ReductTarget reduct_obj)
Teuchos_Ordinal RTOp_index_type
Definition: RTOp.h:68