1 |
ksteube |
1312 |
|
2 |
jgs |
150 |
/* $Id$ */ |
3 |
|
|
|
4 |
ksteube |
1312 |
/******************************************************* |
5 |
|
|
* |
6 |
|
|
* Copyright 2003-2007 by ACceSS MNRF |
7 |
|
|
* Copyright 2007 by University of Queensland |
8 |
|
|
* |
9 |
|
|
* http://esscc.uq.edu.au |
10 |
|
|
* Primary Business: Queensland, Australia |
11 |
|
|
* Licensed under the Open Software License version 3.0 |
12 |
|
|
* http://www.opensource.org/licenses/osl-3.0.php |
13 |
|
|
* |
14 |
|
|
*******************************************************/ |
15 |
dhawcroft |
631 |
|
16 |
jgs |
150 |
/**************************************************************/ |
17 |
|
|
|
18 |
|
|
/* Paso: SystemMatrixPatternPattern */ |
19 |
|
|
|
20 |
|
|
/**************************************************************/ |
21 |
ksteube |
1312 |
|
22 |
|
|
/* Copyrights by ACcESS Australia 2003, 2004,2005, 2006, 2007 */ |
23 |
jgs |
150 |
/* Author: gross@access.edu.au */ |
24 |
|
|
|
25 |
|
|
/**************************************************************/ |
26 |
|
|
|
27 |
|
|
#include "Paso.h" |
28 |
|
|
#include "SystemMatrixPattern.h" |
29 |
|
|
|
30 |
|
|
/**************************************************************/ |
31 |
|
|
|
32 |
|
|
/* allocates a SystemMatrixPattern */ |
33 |
|
|
|
34 |
ksteube |
1312 |
Paso_SystemMatrixPattern* Paso_SystemMatrixPattern_alloc(int type, |
35 |
|
|
Paso_Distribution *output_distribution, |
36 |
|
|
Paso_Distribution *input_distribution, |
37 |
|
|
Paso_Pattern* mainPattern, |
38 |
|
|
Paso_Pattern* couplePattern, |
39 |
|
|
Paso_Coupler* coupler) |
40 |
|
|
{ |
41 |
|
|
Paso_SystemMatrixPattern*out=NULL; |
42 |
|
|
|
43 |
|
|
|
44 |
jgs |
150 |
Paso_resetError(); |
45 |
|
|
|
46 |
ksteube |
1312 |
if (mainPattern->type != type) { |
47 |
|
|
Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: type of mainPattern does not match expected type."); |
48 |
gross |
415 |
} |
49 |
ksteube |
1312 |
if (couplePattern->type != type) { |
50 |
|
|
Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: type of couplePattern does not match expected type."); |
51 |
jgs |
150 |
} |
52 |
ksteube |
1312 |
if ( couplePattern->numOutput != mainPattern->numOutput) { |
53 |
|
|
Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: number of output for couple and main pattern don't match."); |
54 |
jgs |
150 |
} |
55 |
ksteube |
1312 |
if (mainPattern->numOutput != Paso_Distribution_getMyNumComponents(output_distribution)) { |
56 |
|
|
Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: number of output and given distribution don't match."); |
57 |
|
|
} |
58 |
|
|
if (mainPattern->numInput != Paso_Distribution_getMyNumComponents(input_distribution)) { |
59 |
|
|
Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: number of input for main pattern and number of send components in coupler don't match."); |
60 |
|
|
} |
61 |
|
|
if (couplePattern->numInput != coupler->recv->numSharedComponents) { |
62 |
|
|
Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: number of inputs for couple pattern and number of received components in coupler don't match."); |
63 |
|
|
} |
64 |
|
|
if (mainPattern->output_block_size != couplePattern->output_block_size) { |
65 |
|
|
Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: output block sizes of main and couple pattern do not match."); |
66 |
|
|
} |
67 |
|
|
if (mainPattern->input_block_size != couplePattern->input_block_size) { |
68 |
|
|
Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: input block sizes of main and couple pattern do not match."); |
69 |
|
|
} |
70 |
jgs |
150 |
|
71 |
|
|
out=MEMALLOC(1,Paso_SystemMatrixPattern); |
72 |
|
|
if (Paso_checkPtr(out)) return NULL; |
73 |
ksteube |
1312 |
out->type=type; |
74 |
jgs |
150 |
out->reference_counter=1; |
75 |
ksteube |
1312 |
out->mainPattern=Paso_Pattern_getReference(mainPattern); |
76 |
|
|
out->couplePattern=Paso_Pattern_getReference(couplePattern); |
77 |
|
|
out->coupler=Paso_Coupler_getReference(coupler); |
78 |
|
|
out->output_distribution=Paso_Distribution_getReference(output_distribution); |
79 |
|
|
out->input_distribution=Paso_Distribution_getReference(input_distribution); |
80 |
|
|
out->mpi_info= Paso_MPIInfo_getReference(coupler->mpi_info); |
81 |
jgs |
150 |
#ifdef Paso_TRACE |
82 |
|
|
printf("Paso_SystemMatrixPattern_dealloc: system matrix pattern as been allocated.\n"); |
83 |
|
|
#endif |
84 |
|
|
return out; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
/* returns a reference to in */ |
88 |
|
|
|
89 |
|
|
Paso_SystemMatrixPattern* Paso_SystemMatrixPattern_reference(Paso_SystemMatrixPattern* in) { |
90 |
|
|
if (in!=NULL) { |
91 |
|
|
++(in->reference_counter); |
92 |
|
|
} |
93 |
|
|
return in; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
/* deallocates a SystemMatrixPattern: */ |
97 |
|
|
|
98 |
ksteube |
1312 |
void Paso_SystemMatrixPattern_free(Paso_SystemMatrixPattern* in) { |
99 |
jgs |
150 |
if (in!=NULL) { |
100 |
|
|
in->reference_counter--; |
101 |
|
|
if (in->reference_counter<=0) { |
102 |
ksteube |
1312 |
Paso_Pattern_free(in->mainPattern); |
103 |
|
|
Paso_Pattern_free(in->couplePattern); |
104 |
|
|
Paso_Coupler_free(in->coupler); |
105 |
|
|
Paso_Distribution_free(in->output_distribution); |
106 |
|
|
Paso_Distribution_free(in->input_distribution); |
107 |
|
|
Paso_MPIInfo_free(in->mpi_info); |
108 |
jgs |
150 |
MEMFREE(in); |
109 |
|
|
#ifdef Paso_TRACE |
110 |
ksteube |
1312 |
printf("Paso_SystemMatrixPattern_free: system matrix pattern as been deallocated.\n"); |
111 |
jgs |
150 |
#endif |
112 |
|
|
} |
113 |
|
|
} |
114 |
|
|
} |
115 |
gross |
1361 |
dim_t Paso_SystemMatrixPattern_getNumOutput(Paso_SystemMatrixPattern* in) { |
116 |
|
|
if (in!=NULL) { |
117 |
|
|
return 0; |
118 |
|
|
} else { |
119 |
|
|
return in->mainPattern->numOutput; |
120 |
|
|
} |
121 |
|
|
} |
122 |
|
|
|