// File: /workspace/github_cpp_makefile_star2_O3/yukimasano[P]cpp_matrix/vary_N.cpp
// Function: main
int main()
{
	ofstream outfile;
	int i = 1;

	for (int j=15; j<=50; j+=1){

		/* format of output is
		# format    0 N , 1 SD Count, 2 SD Time, 3 CG Count, 4 CG time,
		#           5 CG_pre count 6 CG_pre time
		#           7 LU time, 8 LU delx, 9 QR time, 10 QR delx
		#						11 full QR time 12 full QR delx
		*/

		double sd_co =0.0;
		double sd_ti =0.0;
		double cg_co =0.0;
		double cg_ti =0.0;
		double cgp_co =0.0;
		double cgp_ti =0.0;
		double lu_ti =0.0;
		double lu_dx =0.0;
		double qr_ti =0.0;
		double qr_dx =0.0;
		double qre_ti =0.0;
		double qre_dx =0.0;
    i = pow(1.09,j)+8;
		outfile<<i<<",";



		// for loop to average measurements
	  for (int k=0;k<=10 ;k++){
			////// VERSION SAME KAPPA DIFFERENT SIZE N
			clock_t begin = clock();
			Vector x(i);
			x = randv(x);
			Matrix Q(i,i);
			Q = rand_basis_gs(Q);
			Matrix QT=Q.T();
			Matrix A(i,i);
			A = Q;
			double k0 = 2.0;
			for (int jj=1; jj<=i;  jj++){
				double x = ((k0-1)/float(i-1))*float(jj) + 1.;
				for (int h =1; h<=i; h++){
					A.set_val(jj,h, A(jj,h)*x);
				}
			}
			Vector b = A*x;
			clock_t end = clock();
			double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
			cout<<"dim = "<<i<<" time for prep: "<<elapsed_secs<<endl;

			int count = 0;
	    //// code starts here /////////////////////////////////////
			begin = clock();
			count = 0;
			Vector x1 = SD(A,b, count);
			end = clock();
			elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
      sd_ti += elapsed_secs;
			sd_co += count;

			begin = clock();
			count = 0;
			x1 = CG(A,b, count);
			end = clock();
			elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
			cg_ti += elapsed_secs;
			cg_co += count;

			begin = clock();
			count = 0;
			x1 = CG_pre(A,b, count);
			end = clock();
			elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
			cgp_ti += elapsed_secs;
			cgp_co += count;

			////////////////// non-iterative solvers
			begin = clock();
			x1 = LUsolve(A,b);
			end = clock();
			elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
			double delx = (x1 - x).norm();
			lu_ti += elapsed_secs;
			lu_dx += delx;

			if (i<200){
				//cout<<"QR2"<<flush<<endl;
			  begin = clock();
				x1 = QRsolve2(A,b);
				end = clock();
				elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
				delx = (x1 - x).norm();
				qr_ti += elapsed_secs;
				qr_dx += delx;
			}
			else{
				qr_ti = 0;
				qr_dx = 0;
			}
			//cout<<"QRs"<<flush<<endl;
      if (i<100){
				begin = clock();
				x1 = QRsolve(A,b);
				end = clock();
				elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
				delx = (x1 - x).norm();
				qre_ti += elapsed_secs;
				qre_dx += delx;
			}
			else{
				qre_ti = 0;
				qre_dx = 0;
			}
		}
		//cout<<"done"<<flush<<endl;
		outfile.open("varyN_kappa2.txt", fstream::app);
		outfile<< sd_co/10<<","<< sd_ti/10 << ",";
		outfile<< cg_co/10<<","<< cg_ti/10 << ",";
		outfile<< cgp_co/10<<","<< cgp_ti/10 << ",";
		outfile<< lu_ti/10<<","<< lu_dx/10 << ",";
		outfile<< qr_ti/10<<","<< qr_dx/10 << ",";
		outfile<< qre_ti/10<<","<< qre_dx/10<<",";
		outfile<<endl;
		outfile.flush();
		outfile.close();
	}

  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x348, %rsp            # imm = 0x348
leaq 0x148(%rsp), %r14
movq %r14, %rdi
callq 0x21b0
movl $0xf, %eax
leaq 0x6c47(%rip), %r15      # 0x9030
leaq 0x128(%rsp), %r13
leaq 0x138(%rsp), %rbp
movl %eax, 0xcc(%rsp)
cvtsi2sd %eax, %xmm1
movsd 0x6bfc(%rip), %xmm0     # 0x9008
callq 0x21e0
addsd 0x6bf7(%rip), %xmm0     # 0x9010
cvttsd2si %xmm0, %esi
movq %r14, %rdi
movq %rsi, 0x8(%rsp)
callq 0x21d0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movq 0x8(%rsp), %r15
leal -0x1(%r15), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x6bc2(%rip), %xmm1     # 0x9018
divsd %xmm0, %xmm1
movsd %xmm1, 0x110(%rsp)
negl %r15d
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %r12d, %r12d
movsd %xmm0, 0x20(%rsp)
movsd %xmm0, 0x30(%rsp)
movsd %xmm0, 0x38(%rsp)
movsd %xmm0, 0x80(%rsp)
movsd %xmm0, 0x78(%rsp)
movsd %xmm0, 0x90(%rsp)
movsd %xmm0, 0x88(%rsp)
movsd %xmm0, 0xa0(%rsp)
movsd %xmm0, 0x98(%rsp)
movsd %xmm0, 0xb0(%rsp)
movsd %xmm0, 0xa8(%rsp)
callq 0x20c0
movq %rax, 0x70(%rsp)
movq %r13, %rdi
movq 0x8(%rsp), %rsi
callq 0x81e8
leaq 0xd0(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x8e6d
movq %r13, %rdi
movq %rbx, %rsi
callq 0x893a
movq %rbx, %rdi
callq 0x827e
movq %rbx, %rdi
movq 0x8(%rsp), %rdx
movl %edx, %esi
callq 0x2e94
leaq 0x118(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3ea9
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3574
movq %r14, %rdi
callq 0x2f1c
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3114
movq %rbp, %rdi
movq 0x8(%rsp), %rdx
movl %edx, %esi
callq 0x2e94
movq %rbp, %rdi
leaq 0xd0(%rsp), %rsi
callq 0x3574
movl %r12d, 0x14(%rsp)
movq %r13, %rbx
movq 0x8(%rsp), %r13
testl %r13d, %r13d
jle 0x25ec
movl $0x1, %r14d
xorps %xmm0, %xmm0
cvtsi2ss %r14d, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x110(%rsp), %xmm0
addsd 0x6a7d(%rip), %xmm0     # 0x9018
movsd %xmm0, 0x28(%rsp)
movl $0x1, %r12d
movq %rbp, %rdi
movl %r14d, %esi
movl %r12d, %edx
callq 0x2f5c
movsd (%rax), %xmm0
mulsd 0x28(%rsp), %xmm0
movq %rbp, %rdi
movl %r14d, %esi
movl %r12d, %edx
callq 0x3900
leal (%r15,%r12), %eax
incl %eax
movl %r12d, %ecx
incl %ecx
movl %ecx, %r12d
cmpl $0x1, %eax
jne 0x25a7
leal 0x1(%r14), %eax
cmpl %r13d, %r14d
movl %eax, %r14d
jne 0x257e
leaq 0xb8(%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x3915
callq 0x20c0
subq 0x70(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x6a07(%rip), %xmm0     # 0x9020
movsd %xmm0, 0x28(%rsp)
movl $0x6, %edx
movq 0xa9a5(%rip), %rbx      # 0xcfd0
movq %rbx, %rdi
leaq 0x69fd(%rip), %rsi      # 0x9032
callq 0x2160
movq %rbx, %rdi
movl %r13d, %esi
callq 0x21d0
movq %rax, %rbx
movl $0x10, %edx
movq %rax, %rdi
leaq 0x69e2(%rip), %rsi      # 0x9039
callq 0x2160
movq %rbx, %rdi
movsd 0x28(%rsp), %xmm0
callq 0x21a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
xorl %r14d, %r14d
movl %r14d, 0x4(%rsp)
callq 0x20c0
movq %rax, %rbx
movl %r14d, 0x4(%rsp)
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
leaq 0xb8(%rsp), %r14
movq %r14, %rdx
leaq 0x4(%rsp), %r13
movq %r13, %rcx
callq 0x7122
callq 0x20c0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x693f(%rip), %xmm0     # 0x9020
movsd %xmm0, 0x28(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
callq 0x20c0
movq %rax, %rbx
movl $0x0, 0x4(%rsp)
leaq 0x50(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x73bc
leaq 0x40(%rsp), %rdi
movq %r12, %rsi
callq 0x893a
movq %r12, %rdi
callq 0x827e
callq 0x20c0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x68d7(%rip), %xmm0     # 0x9020
movsd %xmm0, 0x108(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%rsp), %xmm0
movsd %xmm0, 0x100(%rsp)
callq 0x20c0
movq %rax, %rbx
movl $0x0, 0x4(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
leaq 0xb8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
callq 0x789d
leaq 0x40(%rsp), %rdi
movq %r12, %rsi
callq 0x893a
movq %r12, %rdi
callq 0x827e
callq 0x20c0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x6867(%rip), %xmm0     # 0x9020
movsd %xmm0, 0xf8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%rsp), %xmm0
movsd %xmm0, 0xf0(%rsp)
callq 0x20c0
movq %rax, %rbx
movq %r12, %rdi
movq %rbp, %rsi
leaq 0xb8(%rsp), %rdx
callq 0x4919
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x893a
movq %r12, %rdi
callq 0x827e
callq 0x20c0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x6801(%rip), %xmm0     # 0x9020
movsd %xmm0, 0xe8(%rsp)
movq %r12, %rdi
movq %r14, %rsi
leaq 0x128(%rsp), %r13
movq %r13, %rdx
callq 0x8428
movq %r12, %rdi
movl $0x2, %esi
callq 0x8d68
movsd %xmm0, 0xe0(%rsp)
movq %r12, %rdi
callq 0x827e
cmpl $0xc7, 0x8(%rsp)
jg 0x29ad
callq 0x20c0
movq %rax, %rbx
movq %r12, %rdi
movq %rbp, %rsi
leaq 0xb8(%rsp), %rdx
callq 0x569f
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x893a
movq %r12, %rdi
callq 0x827e
callq 0x20c0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x676b(%rip), %xmm0     # 0x9020
movsd %xmm0, 0x68(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x8428
movq %r12, %rdi
movl $0x2, %esi
callq 0x8d68
movq %r12, %rdi
movsd %xmm0, 0x60(%rsp)
callq 0x827e
movsd 0x38(%rsp), %xmm0
addsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x30(%rsp), %xmm0
addsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
cmpl $0x63, 0x8(%rsp)
jg 0x29bf
callq 0x20c0
movq %rax, %rbx
movq %r12, %rdi
movq %rbp, %rsi
leaq 0xb8(%rsp), %rdx
callq 0x4d1e
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x893a
movq %r12, %rdi
callq 0x827e
callq 0x20c0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x66c2(%rip), %xmm0     # 0x9020
movsd %xmm0, 0x68(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x8428
movq %r12, %rdi
movl $0x2, %esi
callq 0x8d68
movsd %xmm0, 0x60(%rsp)
movq %r12, %rdi
callq 0x827e
movsd 0x20(%rsp), %xmm0
addsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x18(%rsp), %xmm0
addsd 0x60(%rsp), %xmm0
jmp 0x29c9
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd %xmm0, 0x38(%rsp)
jmp 0x29c3
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd %xmm0, 0x18(%rsp)
leaq 0x40(%rsp), %rdi
movl 0x14(%rsp), %r12d
movsd 0xb0(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
movsd %xmm0, 0xb0(%rsp)
movsd 0xa8(%rsp), %xmm0
addsd 0x70(%rsp), %xmm0
movsd %xmm0, 0xa8(%rsp)
movsd 0xa0(%rsp), %xmm0
addsd 0x108(%rsp), %xmm0
movsd %xmm0, 0xa0(%rsp)
movsd 0x98(%rsp), %xmm0
addsd 0x100(%rsp), %xmm0
movsd %xmm0, 0x98(%rsp)
movsd 0x90(%rsp), %xmm0
addsd 0xf8(%rsp), %xmm0
movsd %xmm0, 0x90(%rsp)
movsd 0x88(%rsp), %xmm0
addsd 0xf0(%rsp), %xmm0
movsd %xmm0, 0x88(%rsp)
movsd 0x78(%rsp), %xmm0
addsd 0xe8(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x80(%rsp), %xmm0
addsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
callq 0x827e
leaq 0xb8(%rsp), %rdi
callq 0x827e
movq %rbp, %rdi
callq 0x2f1c
leaq 0x118(%rsp), %rdi
callq 0x2f1c
leaq 0xd0(%rsp), %rdi
callq 0x2f1c
movq %r13, %rdi
callq 0x827e
incl %r12d
cmpl $0xb, %r12d
jne 0x24ca
leaq 0x148(%rsp), %r14
movq %r14, %rdi
leaq 0x654a(%rip), %rsi      # 0x904a
movl $0x1, %edx
callq 0x2050
leaq 0x651f(%rip), %r15      # 0x9030
movsd 0xa8(%rsp), %xmm0
divsd 0x6506(%rip), %xmm0     # 0x9028
movq %r14, %rdi
callq 0x21a0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0xb0(%rsp), %xmm0
divsd 0x64da(%rip), %xmm0     # 0x9028
movq %rbx, %rdi
callq 0x21a0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x98(%rsp), %xmm0
divsd 0x64b1(%rip), %xmm0     # 0x9028
movq %r14, %rdi
callq 0x21a0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0xa0(%rsp), %xmm0
divsd 0x6485(%rip), %xmm0     # 0x9028
movq %rbx, %rdi
callq 0x21a0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x88(%rsp), %xmm0
divsd 0x645c(%rip), %xmm0     # 0x9028
movq %r14, %rdi
callq 0x21a0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x90(%rsp), %xmm0
divsd 0x6430(%rip), %xmm0     # 0x9028
movq %rbx, %rdi
callq 0x21a0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x78(%rsp), %xmm0
divsd 0x640a(%rip), %xmm0     # 0x9028
movq %r14, %rdi
callq 0x21a0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x80(%rsp), %xmm0
divsd 0x63de(%rip), %xmm0     # 0x9028
movq %rbx, %rdi
callq 0x21a0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x38(%rsp), %xmm0
divsd 0x63b8(%rip), %xmm0     # 0x9028
movq %r14, %rdi
callq 0x21a0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x30(%rsp), %xmm0
divsd 0x638f(%rip), %xmm0     # 0x9028
movq %rbx, %rdi
callq 0x21a0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x20(%rsp), %xmm0
divsd 0x6369(%rip), %xmm0     # 0x9028
movq %r14, %rdi
callq 0x21a0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x18(%rsp), %xmm0
divsd 0x6340(%rip), %xmm0     # 0x9028
movq %rbx, %rdi
callq 0x21a0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movq 0x148(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movq %r14, %rdi
callq 0x20d0
movq %r14, %rdi
callq 0x2180
movl 0xcc(%rsp), %eax
incl %eax
cmpl $0x33, %eax
jne 0x23f9
movq 0xa273(%rip), %rax      # 0xcfc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x150(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x148(%rsp,%rcx)
callq 0x2120
leaq 0x240(%rsp), %rdi
callq 0x2070
movl $0x1, %eax
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2db9
jmp 0x2dc8
jmp 0x2db9
jmp 0x2dc8
jmp 0x2db9
jmp 0x2db9
jmp 0x2dc8
jmp 0x2dc8
jmp 0x2db9
jmp 0x2dc8
jmp 0x2dc8
jmp 0x2dc8
jmp 0x2db9
jmp 0x2db9
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x827e
jmp 0x2dcb
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x827e
jmp 0x2e0e
jmp 0x2e0b
jmp 0x2e1d
jmp 0x2def
jmp 0x2de1
jmp 0x2de6
movq %rax, %rbx
jmp 0x2e3a
movq %rax, %rbx
jmp 0x2e2d
jmp 0x2e06
jmp 0x2e1d
movq %rax, %rbx
jmp 0x2e47
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x827e
jmp 0x2e47
movq %rax, %rbx
jmp 0x2e54
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x827e
jmp 0x2e20
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x2f1c
leaq 0x118(%rsp), %rdi
callq 0x2f1c
leaq 0xd0(%rsp), %rdi
callq 0x2f1c
leaq 0x128(%rsp), %rdi
callq 0x827e
movq 0xa16d(%rip), %rax      # 0xcfc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x150(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x148(%rsp,%rcx)
callq 0x2120
leaq 0x240(%rsp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x21f0