-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproject2_Delaunoy_Crasset_SPARSE.h
193 lines (174 loc) · 5.14 KB
/
project2_Delaunoy_Crasset_SPARSE.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#ifndef SPARSE_H_
#define SPARSE_H_
/**
* Structure representing a sparse matrix
*/
typedef struct SparseMatrix_t SparseMatrix;
/**
* Structure representing a sparse vector
*/
typedef struct SparseVector_t SparseVector;
/**
* Allocate a SparseVector structure
*
* Parameters:
* maxNbElements: The maximum number of element this vector can contain
*
* Returns:
* A pointer to the allocated SparseVector structure
*/
SparseVector* createSparseVector(unsigned int maxNbElements);
/**
* Free a SparseVector structure
*
* Parameters:
* vec: A pointer to the structure to free
*/
void freeSparseVector(SparseVector* vec);
/**
* Allocate a SparseMatrix structure
*
* Parameters:
* begin: The starting row index of the matrix
* end: The ending row index of the matrix
* maxNbElements: The maximum number of elements each of its vectors can contain
*
* Returns:
* A pointer to the allocated structure
*/
SparseMatrix* createSparseMatrix(unsigned int begin, unsigned int end, unsigned int maxNbElements);
/**
* Free a SparseMatrix structure
*
* Parameters:
* mat: A pointer to the structure to free
*/
void freeSparseMatrix(SparseMatrix* mat);
/**
* Print a SparseVector structure
*
* Parameters:
* vec: A pointer to the SparseVector to print
* row: The row this vector is associated with
*/
void printSparseVector(const SparseVector* vec, int row);
/**
* Print a SparseMatrix structure
*
* Parameters:
* mat: A pointer to the SparseMatrix to print
*/
void printSparseMatrix(const SparseMatrix* mat);
/**
* Perform dot product between a SparseVector and an array
*
* Parameters:
* vec1: A pointer to the SparseVector
* vec2: A pointer to the array
*
* Returns:
* The dot product of vec1 and vec2
*/
double vecSparseDotProduct(const SparseVector* vec1, const double* vec2);
/**
* Perform dot product between a row of a SparseMatrix and a SparseVector
*
* Parameters:
* mat: A pointer to the sparseMatrix
* row: The row of the SparseMatrix to use
* vector: A pointer to the SparseVector
*
* Returns:
* The dot product between the row 'row' of mat and vector
*/
double sparseDotProduct(const SparseMatrix* mat, unsigned int row, const double* vector);
/**
* Insert an element in a sparse vector
*
* Parameters:
* vec: A pointer to the SparseVector
* j: The indices at which to insert the element
* elem: The value to insert
*/
void sparseVecInsertElement(SparseVector* vec, unsigned int j, double elem);
/**
* Insert an element in a sparse matrix
*
* Parameters:
* mat: A pointer to a SparseMatrix
* i: The row at which to insert the element
* j: The column at which to insert the element
* elem: The value to insert
*/
void sparseInsertElement(SparseMatrix* mat, unsigned int i, unsigned int j, double elem);
/**
* Reset a SparseVector removing all its elements.
*
* Parameters:
* vec: A pointer to the SparseVector to reset
*/
void resetSparseVector(SparseVector* vec);
/**
* Reset a SparseMatrix removing all its elements.
*
* Parameters:
* mat: A pointer to the SparseMatrix to reset
*/
void resetSparseMatrix(SparseMatrix * mat);
/**
* Perform dot product between to vectors in parallel
*
* Parameters:
* x: A pointer to the first vector
* y: A pointer to the second vector
* size: The size of the vectors
* startIndex: The starting index the calling process is responsible for
* endIndex: The ending index the calling process is responsible for
* myrank: The rank of the calling process
* nbproc: The number of processes
*
* Returns:
* The dot product between the row 'row' of mat and vector
*/
double MPIDotProduct(const double* x, const double* y, unsigned int size, unsigned int startIndex, unsigned int endIndex, int myrank, int nbproc);
/**
* Perform A matrix multiplication between a SparseMatrix and an array in parallel
*
* Parameters:
* A: A pointer to the SparseMatrix
* x: A pointer to the array
* tmpBuff: A pointer to a buffer used for computation
* result: A pointer to an array which elements will be set to the result.
* startIndex: The starting index the calling process is responsible for
* endIndex: The ending index the calling process is responsible for
* myrank: The rank of the calling process
* nbproc: The number of processes
*
* Returns:
* The dot product between the row 'row' of mat and vector
*/
void MPIMatVecMul(const SparseMatrix* A, const double* x, double* tmpBuff, double* result, unsigned int startIndex, unsigned int endIndex, int myrank, int nbproc, int* recvcounts, int* displs);
/**
* Perform dot product between two SparseVectors
*
* Parameters:
* vec1: A pointer to the first SparseVector
* vec2: A pointer to the second SparseVector
*
* Returns:
* The dot product between the two SparseVectors
*/
double sparseVecVecDotProduct(const SparseVector* vec1, const SparseVector* vec2);
/**
* Perform dot product between a row of a SparseMatrix and a SparseVector
*
* Parameters:
* mat: A pointer to the SparseMatrix
* row: The row of the SparseMatrix to use
* vec: A pointer to the SparseVector
*
* Returns:
* The dot product between the row 'row' of mat and vec
*/
double sparseMatVecDotProduct(const SparseMatrix* mat, unsigned int row, const SparseVector* vec);
#endif