Skip to content

Commit 32aca00

Browse files
FoadsfFoadsf
authored andcommitted
some minor edits
1 parent 4594bb2 commit 32aca00

File tree

11 files changed

+174
-0
lines changed

11 files changed

+174
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,4 @@ $RECYCLE.BIN/
142142
*.zip
143143

144144
*.pdf
145+
*.ppt

A_fortran/readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ sources to be looked at:
1919
7. iso_c_binding
2020
8. https://docs.oracle.com/cd/E19059-01/stud.9/817-6694/11_cfort.html
2121
9. https://www.math.utah.edu/software/c-with-fortran.html
22+
10. https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/290051
2223

2324
points:
2425

File renamed without changes.
File renamed without changes.
File renamed without changes.

C_CBLAS/seehuhn/example2/matroot.c

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/* matroot.c - calculate the square root of a matrix
2+
*
3+
* Copyright (C) 2004 Jochen Voss.
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* $Id: matroot.c 7208 2006-09-03 16:11:08Z voss $
16+
*/
17+
18+
#include <stdio.h>
19+
#include <stdlib.h>
20+
#include <string.h>
21+
#include <math.h>
22+
#include <cblas.h>
23+
24+
25+
static const int N = 7;
26+
27+
28+
static void
29+
set_entry(double *A, int i, int j, double val)
30+
{
31+
A[j*N+i] = val;
32+
}
33+
34+
static double
35+
get_entry(const double *A, int i, int j)
36+
{
37+
return A[j*N+i];
38+
}
39+
40+
static int
41+
dsyevr(char JOBZ, char RANGE, char UPLO, int N,
42+
double *A, int LDA, double VL, double VU,
43+
int IL, int IU, double ABSTOL, int *M,
44+
double *W, double *Z, int LDZ, int *ISUPPZ,
45+
double *WORK, int LWORK, int *IWORK, int LIWORK)
46+
{
47+
extern void dsyevr_(char *JOBZp, char *RANGEp, char *UPLOp, int *Np,
48+
double *A, int *LDAp, double *VLp, double *VUp,
49+
int *ILp, int *IUp, double *ABSTOLp, int *Mp,
50+
double *W, double *Z, int *LDZp, int *ISUPPZ,
51+
double *WORK, int *LWORKp, int *IWORK, int *LIWORKp,
52+
int *INFOp);
53+
int INFO;
54+
dsyevr_(&JOBZ, &RANGE, &UPLO, &N, A, &LDA, &VL, &VU,
55+
&IL, &IU, &ABSTOL, M, W, Z, &LDZ, ISUPPZ,
56+
WORK, &LWORK, IWORK, &LIWORK, &INFO);
57+
return INFO;
58+
}
59+
60+
static double
61+
dlamch(char CMACH)
62+
{
63+
extern double dlamch_(char *CMACHp);
64+
return dlamch_(&CMACH);
65+
}
66+
67+
int
68+
main()
69+
{
70+
double *A, *B, *W, *Z, *WORK;
71+
int *ISUPPZ, *IWORK;
72+
int i, j;
73+
int M;
74+
75+
/* allocate and initialise the matrix */
76+
A = malloc(N*N*sizeof(double));
77+
for (i=0; i<N; ++i) {
78+
for (j=0; j<i-1; ++j) {
79+
set_entry(A, i, j, 0);
80+
}
81+
}
82+
for (i=0; i<N-1; ++i) set_entry(A, i+1, i, -1);
83+
for (i=1; i<N-1; ++i) set_entry(A, i, i, 2);
84+
set_entry(A, 0, 0, 1);
85+
set_entry(A, N-1, N-1, 1);
86+
87+
/* allocate space for the output parameters and workspace arrays */
88+
W = malloc(N*sizeof(double));
89+
Z = malloc(N*N*sizeof(double));
90+
ISUPPZ = malloc(2*N*sizeof(int));
91+
WORK = malloc(26*N*sizeof(double));
92+
IWORK = malloc(10*N*sizeof(int));
93+
94+
/* get the eigenvalues and eigenvectors */
95+
dsyevr('V', 'A', 'L', N, A, N, 0, 0, 0, 0, dlamch('S'), &M,
96+
W, Z, N, ISUPPZ, WORK, 26*N, IWORK, 10*N);
97+
98+
/* allocate and initialise a new matrix B=Z*D */
99+
B = malloc(N*N*sizeof(double));
100+
for (j=0; j<N; ++j) {
101+
double lambda=sqrt(W[j]);
102+
for (i=0; i<N; ++i) {
103+
set_entry(B, i, j, get_entry(Z,i,j)*lambda);
104+
}
105+
}
106+
107+
/* calculate the square root A=B*Z^T */
108+
cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans, N, N, N,
109+
1, B, N, Z, N, 0, A, N);
110+
111+
/* emit the result */
112+
for (i=0; i<N; ++i) {
113+
for (j=0; j<N; ++j) {
114+
double x = get_entry(A, i, j);
115+
printf("%6.2f", x);
116+
}
117+
putchar('\n');
118+
}
119+
putchar('\n');
120+
121+
/* check the result by calculating A*A */
122+
memcpy(B, A, N*N*sizeof(double));
123+
cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, N, N, N,
124+
1, A, N, B, N, 0, Z, N);
125+
126+
for (i=0; i<N; ++i) {
127+
for (j=0; j<N; ++j) {
128+
double x = get_entry(Z, i, j);
129+
printf("%6.2f", x);
130+
}
131+
putchar('\n');
132+
}
133+
134+
return 0;
135+
}

C_CBLAS/seehuhn/example2/readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source: http://www.seehuhn.de/pages/matrixfn
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <lapacke.h>
2+
#include <stdio.h>
3+
4+
void print_mtrx(double *mtrx, int n, int m) {
5+
int i, j;
6+
7+
for (i = 0; i < n; i++) {
8+
for (j = 0; j < m; j++) {
9+
printf("%f ", mtrx[i * m + j]);
10+
}
11+
printf("\n");
12+
}
13+
printf("\n");
14+
}
15+
16+
int main() {
17+
double diagonal[5] = {5, 1, 5, 1, 5};
18+
double subdiagonal[4] = {0, 0, 0, 0};
19+
20+
double solution[5] = {1, 2, 3, 4, 5};
21+
22+
LAPACKE_dptsv(LAPACK_ROW_MAJOR, 5 /*size of matrix*/,
23+
1 /*number of columns in solution*/, diagonal, subdiagonal,
24+
solution, 1 /*leading dimension of solution vector*/);
25+
26+
print_mtrx(solution, 5, 1);
27+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source: http://stackoverflow.com/questions/28177740/solving-linear-equation-with-lapacke

H_ATLAS/readme.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sources to be explored:
2+
1. http://stackoverflow.com/questions/3146274/is-it-ok-to-use-dyld-library-path-on-mac-os-x-and-whats-the-dynamic-library-s/3172515#3172515

0 commit comments

Comments
 (0)