1 |
|
2 |
/* $Id$ */ |
3 |
|
4 |
/******************************************************* |
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 |
|
16 |
/**************************************************************/ |
17 |
|
18 |
/* Paso: SystemMatrixPatternPattern */ |
19 |
|
20 |
/**************************************************************/ |
21 |
|
22 |
/* Copyrights by ACcESS Australia 2003, 2004,2005, 2006, 2007 */ |
23 |
/* 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 |
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 |
Paso_resetError(); |
45 |
|
46 |
if (mainPattern->type != type) { |
47 |
Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: type of mainPattern does not match expected type."); |
48 |
} |
49 |
if (couplePattern->type != type) { |
50 |
Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: type of couplePattern does not match expected type."); |
51 |
} |
52 |
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 |
} |
55 |
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 |
|
71 |
out=MEMALLOC(1,Paso_SystemMatrixPattern); |
72 |
if (Paso_checkPtr(out)) return NULL; |
73 |
out->type=type; |
74 |
out->reference_counter=1; |
75 |
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 |
#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 |
void Paso_SystemMatrixPattern_free(Paso_SystemMatrixPattern* in) { |
99 |
if (in!=NULL) { |
100 |
in->reference_counter--; |
101 |
if (in->reference_counter<=0) { |
102 |
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 |
MEMFREE(in); |
109 |
#ifdef Paso_TRACE |
110 |
printf("Paso_SystemMatrixPattern_free: system matrix pattern as been deallocated.\n"); |
111 |
#endif |
112 |
} |
113 |
} |
114 |
} |
115 |
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 |
|