2008 ( 13 ) C LAPACK 2008 ( 13 )C LAPACK p. 1

Similar documents
file"a" file"b" fp = fopen("a", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose(fp); fp = fopen("b", "r"); while(fgets(line, BUFSIZ, fp)) {... fclose

comment.dvi

C による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. このサンプルページの内容は, 新装版 1 刷発行時のものです.

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

C

AutoTuned-RB

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裱£²²ó ¡Ý½ÉÂꣲ¤Î²òÀ⡤±é½¬£²¡Ý

1.ppt

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() 2 double *a[ ]; double 1 malloc() dou

1 1.1 C 2 1 double a[ ][ ]; 1 3x x3 ( ) malloc() malloc 2 #include <stdio.h> #include

BW BW

r07.dvi

ohp07.dvi

sim98-8.dvi

double float

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

£Ã¥×¥í¥°¥é¥ß¥ó¥°(2018) - Âè11²ó – ½ÉÂꣲ¤Î²òÀ⡤±é½¬£² –

新・明解C言語 実践編

Gauss

実際の株価データを用いたオプション料の計算

新版明解C言語 実践編

1 4 2 EP) (EP) (EP)

lexex.dvi

C 2 / 21 1 y = x 1.1 lagrange.c 1 / Laglange / 2 #include <stdio.h> 3 #include <math.h> 4 int main() 5 { 6 float x[10], y[10]; 7 float xx, pn, p; 8 in

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n

Microsoft Word - C.....u.K...doc

新・明解C言語 ポインタ完全攻略

XMPによる並列化実装2

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B

8 / 0 1 i++ i 1 i-- i C !!! C 2

超初心者用


#define N1 N+1 double x[n1] =.5, 1., 2.; double hokan[n1] = 1.65, 2.72, 7.39 ; double xx[]=.2,.4,.6,.8,1.2,1.4,1.6,1.8; double lagrng(double xx); main

tuat1.dvi

untitled

memo

x h = (b a)/n [x i, x i+1 ] = [a+i h, a+ (i + 1) h] A(x i ) A(x i ) = h 2 {f(x i) + f(x i+1 ) = h {f(a + i h) + f(a + (i + 1) h), (2) 2 a b n A(x i )

j x j j j + 1 l j l j = x j+1 x j, n x n x 1 = n 1 l j j=1 H j j + 1 l j l j E


1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return 0; 戻り値 1: main() 2.2 C main

Untitled

r08.dvi

橡CompSimmAllcpct.PDF

CM-3G 周辺モジュール拡張技術文書 MS5607センサ(温度、気圧)

& & a a * * ptr p int a ; int *a ; int a ; int a int *a

ohp08.dvi

ex01.dvi

スライド 1

QR

A

Taro-リストⅢ(公開版).jtd

資料

ohp03.dvi

スライド 1

memo

t 2 2 t 2 t F ( ) p- 2 2 F 2 G F ( ) 2 2 F 2 G F ( ) 2 2 2

スライド 1

Taro-ファイル処理(公開版).jtd

Microsoft Word - Cプログラミング演習(12)

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

6 6.1 sound_wav_files flu00.wav.wav 44.1 khz 1/44100 spwave Text with Time spwave t T = N t N 44.1 khz t = 1 sec j t f j {f 0, f 1, f 2,, f N 1

programmingII2019-v01

ex14.dvi

I 2 tutimura/ I 2 p.1/??

第5回お試しアカウント付き並列プログラミング講習会


c-all.dvi

PowerPoint プレゼンテーション

‚æ2›ñ C„¾„ê‡Ìš|

P06.ppt

プログラミング基礎

ohp11.dvi

r11.dvi

USB ID TA DUET 24:00 DUET XXX -YY.c ( ) XXX -YY.txt() XXX ID 3 YY ID 5 () #define StudentID 231

11042 計算機言語7回目 サポートページ:

Cプログラミング1(再) 第2回

program.dvi

44 6 MPI 4 : #LIB=-lmpich -lm 5 : LIB=-lmpi -lm 7 : mpi1: mpi1.c 8 : $(CC) -o mpi1 mpi1.c $(LIB) 9 : 10 : clean: 11 : -$(DEL) mpi1 make mpi1 1 % mpiru

p = 1, 2, cos 2n + p)πj = cos 2nπj 2n + p)πj, sin = sin 2nπj 7.1) f j = a ) 0 + a p + a n+p cos 2nπj p=1 p=0 1 + ) b n+p p=0 sin 2nπj 1 2 a 0 +

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

kiso2-09.key

[ 1] 1 Hello World!! 1 #include <s t d i o. h> 2 3 int main ( ) { 4 5 p r i n t f ( H e l l o World!! \ n ) ; 6 7 return 0 ; 8 } 1:

ex01.dvi

IP L09( Tue) : Time-stamp: Tue 14:52 JST hig TCP/IP. IP,,,. ( ) L09 IP (2017) 1 / 28

slide5.pptx

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( )

memo

‚æ4›ñ

yacc.dvi

untitled

: CR (0x0d) LF (0x0a) line separator CR Mac LF UNIX CR+LF MS-DOS WINDOWS Japan Advanced Institute of Science and Technology

double 2 std::cin, std::cout 1.2 C fopen() fclose() C++ std::fstream 1-3 #include <fstream> std::fstream fout; int a = 123; fout.open( "data.t

untitled

Condition DAQ condition condition 2 3 XML key value

Taro-再帰関数Ⅱ(公開版).jtd

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

関数のグラフを描こう

thesis.dvi

1 4 1 ( ) ( ) ( ) ( ) () 1 4 2

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡

Transcription:

2008 ( 13 ) C LAPACK LAPACK p. 1

Q & A Euler http://phase.hpcc.jp/phase/mppack/long.pdf KNOPPIX MT (Mersenne Twister) SFMT., ( ) ( ) ( ) ( ). LAPACK p. 2

C C, main Asir ( Asir ) ( ) (,,...), LAPACK p. 3

,.c : afo.c } main() { printf("afo\n");, cc afo.c./a.out afo LAPACK p. 4

genb.c : M N : cc -o genb genb.c :./genb 1000 1000 a 1000 1000 ( ) a :./genb 1000 1 b 1000 1 ( ) b solveb.c LAPACK : cc -o solveb solveb.c -llapack -lblas -lg2c :./solveb 1000 a b x ax = b (b 1000 1 ), x LAPACK p. 5

( ) checkb.c : : cc -o checkb checkb.c -llapack -lblas -lg2c :./checkb 1000 a x b ax b 2 mylu.c ( ; 1) : cc -o mylu mylu.c :./mylu 1000 a b x mylu1.c ( ; 2) : cc -o mylu1 mylu1.c :./mylu1 1000 a b x LAPACK p. 6

genb m n (8 ) mn solveb genb, time solveb... LAPACK p. 7

main ( ) #include <stdio.h> #include <stdlib.h> #include <f2c.h> /* */ main(int argc,char **argv) { double *a,*b; } int n,nn; n = atoi(argv[1]); nn = n*n; a = read_matrix(argv[2],nn); b = read_matrix(argv[3],n); ret = lapack_linsolve(a,b,n); if ( ret == 0 ) { write_matrix(argv[4],b,n); } else fprintf(stderr, error\n ); LAPACK p. 8

, LU, LU, lapack_linsolve(a,b,n), dgetrf (LU ), dgetrs ( ) : (a), (b), (read_matrix). LAPACK p. 9

#include <stdio.h> #include <stdlib.h> #include <f2c.h> ( f2c.h LAPACK ) main main(int argc,char **argv) argc : ( ) argv : a.out 123 abc argc=3 argv[0]="a.out" argv[1]="123" argv[2]="abc" LAPACK p. 10

double *a,*b; int n,nn; *, (, ) a = read matrix(argv[1],nn) argv[1], ( ) write matrix(argv[3],b,n) b, argv[3]. LAPACK p. 11

int write_matrix(char *fname,double *a, int len); double *read_matrix(char *fname,int len); int lapack_linsolve(double *m_array, double *b_array,int n);, LAPACK p. 12

(Scilab ), : 8 : 8 ( ), LAPACK p. 13

#include <stdio.h> #include <stdlib.h> #include <f2c.h> double *read_matrix(char *fname,int len){ double *a; FILE *fp; int i; } if (!(fp = fopen(fname,"r")) ) return 0; a = (double *) malloc(len*sizeof(double)); for ( i = 0; i < len; i++ ) fscanf(fp,"%lf",&a[i]); return a; LAPACK p. 14

#include <stdio.h> #include <stdlib.h> #include <f2c.h> double *read_matrix(char *fname,int len){ double *a; FILE *fp; } if (!(fp = fopen(fname,"rb")) ) return 0; a = (double *) malloc(len*sizeof(double)); fread(a,len,sizeof(double),fp); return a; LAPACK p. 15

#include <stdio.h> #include <stdlib.h> #include <f2c.h> int write_matrix(double *a,char *fname, int len){ FILE *fp; int i; } if (!(fp = fopen(fname,"wb")) ) return 0; for ( i = 0; i < len; i++ ) fprintf(fp,"%lf",a[i]); fclose(fp); return 1; LAPACK p. 16

#include <stdio.h> #include <stdlib.h> #include <f2c.h> int write_matrix(double *a,char *fname, int len){ FILE *fp; } if (!(fp = fopen(fname,"wb")) ) return 0; fwrite(a,len,sizeof(double),fp); fclose(fp); return 1; LAPACK p. 17

fp=fopen(fname,"r"), fp=fopen(fname,"w"), open fclose(fp) fscanf(fp,"%lf",&a[i]),, a[i] fread(a,len,sizeof(double),fp) len, a LAPACK p. 18

lapack linsolve int lapack_linsolve(double *a,double *b, int n) { int i,j; int nrhs,lda,ldb,info; int *ipiv; char trans; ipiv = (int *)malloc(n*sizeof(int)); trans = N ; nrhs = 1; lda = n; ldb = n; dgetrf_(&n,&n,a,&lda,ipiv,&info); if ( info ) return -1; dgetrs_(&trans,&n,&nrhs,a,&lda,ipiv, b,&ldb,&info); if ( info ) return -1; return 0; } LAPACK p. 19

ipiv = (int *)malloc(n*sizeof(int)) ipiv dgetrf (&n,&n,a,&lda,ipiv,&info) LU. a. dgetrs (&trans,&n,&nrhs,a,&lda,...) LU ( piv) ax=b. b. lda, ldb : n nrhs ( ) : 1 LAPACK p. 20

, cc -o mylu mylu.c LAPACK cc -o solve solve.c -llapack -lblas -lg2c lxxx libxxx.a, Makefile LAPACK p. 21

Makefile all: sol.c.o: $(CC) -c -g $< clean: $(RM) -rf *.o sol sol: sol.o $(CC) -o sol sol.o -llapack -lblas -lg2c make, LAPACK p. 22

: 1 u = u(x,t) ((x,t) [0, 1] [0,T]), u t = u xx, u(x, 0) = f(x), u(0,t) = 0 h = 1/(m + 1), k = T/(n + 1), r = k/h 2 u ij = u(ih,jk) (i = 0,...,n + 1, j = 0,...,m + 1) u t (ih,jk) u i,j+1 ui,j k, u xx (ih,jk) (u i 1,j+1 2u i,j+1 +u i+1,j+1 )+(u i 1,j 2u i,j +u i+1,j ) 2h 2 ( j, j + 1 u xx ) LAPACK p. 23

Crank-Nicolson u i,0 = u i,n+1 = 0 1 + r r 2 A = r. 2 1 + r........ r C = 2 1 + r r 2 1 r r 2 r. 2 1 r........ r 2 r 2 1 r, AU j+1 = CU j (U j = t (u 1j,...,u mj )) U j+1 = A 1 CU j, U 0 = t (f(h),...,h(mh)) : O(h 2 ) + O(k 2 ) r ( ) h, k LAPACK p. 24

LAPACK LU dgttrf_(int *n,double *l,double *d,double *u,double *u2, int *ipiv,int *info) l : ( n-1), d : ( n), u : ( n-1), u2 : ( n-2; ) l, d, u l, d, u, u2 (, u2 ) LU dgttrs_(int *trans,...) LAPACK p. 25

, m, n, T A, C : malloc U j+1 = A 1 CU j A 1 C (?) A dgttrf_, dgttrs_ ( - ) Scilab LAPACK p. 26

heat1.c cc -o heat1 heat1.o -llapack -latlas -lg2c : heat1 n m T f sol n :, m : T : t [0,T] f : (genb ) sol : : heat.c LAPACK p. 27

, : A,,, 2 malloc,. (C ) al=(double *)malloc((nx-1)*sizeof(double)); ad=(double *)malloc((nx)*sizeof(double)); au=(double *)malloc((nx-1)*sizeof(double)); au2=(double *)malloc((nx-2)*sizeof(double)); for ( i = 0; i < nx-1; i++ ) { al[i] = au[i] = -r/2; ad[i] = 1+r; } ad[nx-1] = 1+r; LAPACK p. 28

- BLAS void mul_td(double *l,double *d,double *u, double *x,double *y,int n) { int i; y[0] = d[0]*x[0]+u[0]*x[1]; for ( i = 1; i < n-1; i++ ) { y[i] = l[i-1]*x[i-1]+d[i]*x[i] +u[i]*x[i+1]; } y[n-1] = l[n-2]*x[n-2]+d[n-1]*x[n-1]; } LAPACK p. 29

U j+1 = A 1 CU j, u ipiv = (int *)malloc(nx*sizeof(int)); dgttrf_(&nx,al,ad,au,au2,ipiv,&info); trans = N ; nrhs = 1; ldb = nx; out = fopen(argv[5],"wb"); for ( i = 0; i < nt; i++ ) { mul_td(cl,cd,cu,u,w,nx); dgttrs_(&trans,&nx,&nrhs,al,ad,au,au2, ipiv,w,&ldb,&info); memcpy(u,w,nx*sizeof(double)); if (!(i%10) ) { /* 10 1 */ for ( j = 0; j < nx; j++ ) fprintf(out,"%lf ",w[j]); fprintf(out,"\n"); } } LAPACK p. 30

Scilab plot, Scilab U j Scilab plot(x) x, x plot, clf : sol, 1000 t=read("sol",-1,1000) ; plot(x); (A ) LAPACK p. 31

Scilab f(x) Fourier, S 1 ( ), etc. LAPACK 8/12 ( ) LAPACK p. 32