// File: /workspace/github_cpp_makefile_star2_O2/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 $0x358, %rsp            # imm = 0x358
leaq 0x158(%rsp), %r14
movq %r14, %rdi
callq 0x2190
pushq $0xf
popq %rax
leaq 0x6c79(%rip), %r15      # 0x9030
leaq 0xd0(%rsp), %rbp
leaq 0x148(%rsp), %rbx
cmpl $0x33, %eax
je 0x2c67
movl %eax, 0xb4(%rsp)
cvtsi2sd %eax, %xmm1
movsd 0x6c25(%rip), %xmm0     # 0x9008
callq 0x21c0
addsd 0x6c20(%rip), %xmm0     # 0x9010
cvttsd2si %xmm0, %esi
movq %r14, %rdi
movq %rsi, 0x18(%rsp)
callq 0x21b0
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
movq 0x18(%rsp), %r13
leal -0x1(%r13), %eax
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x6bf3(%rip), %xmm1     # 0x9018
xorl %eax, %eax
testl %r13d, %r13d
movl $0x0, %ecx
cmovgl %r13d, %ecx
divsd %xmm0, %xmm1
movsd %xmm1, 0x120(%rsp)
incl %ecx
movl %ecx, 0xbc(%rsp)
negl %r13d
xorpd %xmm0, %xmm0
movsd %xmm0, 0xa8(%rsp)
movsd %xmm0, 0x90(%rsp)
movsd %xmm0, 0x98(%rsp)
movsd %xmm0, 0xa0(%rsp)
movsd %xmm0, 0x78(%rsp)
movsd %xmm0, 0x80(%rsp)
movsd %xmm0, 0x88(%rsp)
movsd %xmm0, 0x70(%rsp)
movsd %xmm0, 0x28(%rsp)
movsd %xmm0, 0x30(%rsp)
movsd %xmm0, 0x60(%rsp)
movsd %xmm0, 0x20(%rsp)
cmpl $0xb, %eax
je 0x2a82
movl %eax, 0xb8(%rsp)
callq 0x20c0
movq %rax, 0x68(%rsp)
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x8068
movq %rbp, %rdi
movq %r14, %rsi
callq 0x89e1
movq %r14, %rdi
movq %rbp, %rsi
callq 0x859c
movq %rbp, %rdi
callq 0x8104
movq %rbp, %rdi
movq 0x18(%rsp), %rdx
movl %edx, %esi
callq 0x2d58
leaq 0x138(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x3cb2
movq %rbp, %rdi
movq %r15, %rsi
callq 0x33ce
movq %r15, %rdi
callq 0x2dea
movq %r15, %rdi
movq %rbp, %rsi
callq 0x2f86
movq %rbx, %rdi
movq 0x18(%rsp), %rdx
movl %edx, %esi
callq 0x2d58
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x33ce
leaq 0xc0(%rsp), %r15
pushq $0x1
popq %rbp
cmpl 0xbc(%rsp), %ebp
je 0x25c0
cvtsi2ss %ebp, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x120(%rsp), %xmm0
addsd 0x6a9a(%rip), %xmm0     # 0x9018
movsd %xmm0, 0x10(%rsp)
pushq $0x1
popq %rax
movl %eax, %r12d
leal (%r12,%r13), %eax
cmpl $0x1, %eax
je 0x25bc
movq %rbx, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x2e20
movsd (%rax), %xmm0
mulsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x371a
incl %r12d
jmp 0x258a
incl %ebp
jmp 0x255c
leaq 0x128(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x372f
callq 0x20c0
subq 0x68(%rsp), %rax
cvtsi2sd %rax, %xmm0
divsd 0x6a33(%rip), %xmm0     # 0x9020
movsd %xmm0, 0x10(%rsp)
movq 0xa9d6(%rip), %rdi      # 0xcfd0
leaq 0x6a31(%rip), %rsi      # 0x9032
callq 0x2130
movq %rax, %rdi
movq 0x18(%rsp), %rsi
callq 0x21b0
movq %rax, %rdi
leaq 0x6a1c(%rip), %rsi      # 0x9039
callq 0x2130
movq %rax, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x2180
movq %rax, %rdi
callq 0x2080
andl $0x0, 0xc(%rsp)
callq 0x20c0
movq %rax, %r15
andl $0x0, 0xc(%rsp)
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
leaq 0xc(%rsp), %r12
movq %r12, %rcx
callq 0x704f
callq 0x20c0
subq %r15, %rax
cvtsi2sd %rax, %xmm0
divsd 0x69a9(%rip), %xmm0     # 0x9020
movsd %xmm0, 0x68(%rsp)
cvtsi2sdl 0xc(%rsp), %xmm0
movsd %xmm0, 0x118(%rsp)
callq 0x20c0
movq %rax, %r15
andl $0x0, 0xc(%rsp)
leaq 0x48(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r12, %rcx
callq 0x72e5
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x859c
movq %r14, %rdi
callq 0x8104
callq 0x20c0
subq %r15, %rax
cvtsi2sd %rax, %xmm0
divsd 0x6947(%rip), %xmm0     # 0x9020
movsd %xmm0, 0x110(%rsp)
cvtsi2sdl 0xc(%rsp), %xmm0
movsd %xmm0, 0x108(%rsp)
callq 0x20c0
movq %rax, %r15
andl $0x0, 0xc(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
leaq 0xc(%rsp), %rcx
callq 0x77bb
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x859c
movq %r14, %rdi
callq 0x8104
callq 0x20c0
subq %r15, %rax
cvtsi2sd %rax, %xmm0
divsd 0x68e5(%rip), %xmm0     # 0x9020
movsd %xmm0, 0x100(%rsp)
cvtsi2sdl 0xc(%rsp), %xmm0
movsd %xmm0, 0xf8(%rsp)
callq 0x20c0
movq %rax, %r15
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x474a
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x859c
movq %r14, %rdi
callq 0x8104
callq 0x20c0
subq %r15, %rax
cvtsi2sd %rax, %xmm0
divsd 0x688a(%rip), %xmm0     # 0x9020
movsd %xmm0, 0xf0(%rsp)
movq %r14, %rdi
movq %r12, %rsi
leaq 0xc0(%rsp), %rdx
callq 0x8238
movq %r14, %rdi
pushq $0x2
popq %rsi
callq 0x891a
movsd %xmm0, 0xe8(%rsp)
movq %r14, %rdi
callq 0x8104
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
cmpl $0xc7, 0x18(%rsp)
jg 0x2938
callq 0x20c0
movq %rax, %r15
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x5563
leaq 0xd0(%rsp), %rbp
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x859c
movq %r14, %rdi
callq 0x8104
callq 0x20c0
subq %r15, %rax
cvtsi2sd %rax, %xmm0
divsd 0x67ef(%rip), %xmm0     # 0x9020
movsd %xmm0, 0x58(%rsp)
movq %r14, %rdi
movq %r12, %rsi
leaq 0xc0(%rsp), %rdx
callq 0x8238
movq %r14, %rdi
pushq $0x2
popq %rsi
callq 0x891a
movq %r14, %rdi
movsd %xmm0, 0xe0(%rsp)
callq 0x8104
movsd 0x28(%rsp), %xmm0
addsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x30(%rsp), %xmm0
addsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
cmpl $0x63, 0x18(%rsp)
jg 0x2954
callq 0x20c0
movq %rax, %r15
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x128(%rsp), %rdx
callq 0x4b55
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x859c
movq %r14, %rdi
callq 0x8104
callq 0x20c0
subq %r15, %rax
cvtsi2sd %rax, %xmm0
divsd 0x6740(%rip), %xmm0     # 0x9020
movsd %xmm0, 0x10(%rsp)
movq %r14, %rdi
movq %r12, %rsi
leaq 0xc0(%rsp), %rdx
callq 0x8238
movq %r14, %rdi
pushq $0x2
popq %rsi
callq 0x891a
movsd %xmm0, 0x58(%rsp)
movq %r14, %rdi
callq 0x8104
movsd 0x60(%rsp), %xmm1
addsd 0x10(%rsp), %xmm1
movsd 0x20(%rsp), %xmm0
addsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd %xmm1, 0x10(%rsp)
jmp 0x295e
movsd %xmm0, 0x30(%rsp)
movsd %xmm0, 0x28(%rsp)
movsd %xmm0, 0x20(%rsp)
leaq 0xd0(%rsp), %rbp
jmp 0x295e
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x38(%rsp), %rdi
movsd 0x90(%rsp), %xmm0
addsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x90(%rsp)
movsd 0xa8(%rsp), %xmm0
addsd 0x118(%rsp), %xmm0
movsd %xmm0, 0xa8(%rsp)
movsd 0xa0(%rsp), %xmm0
addsd 0x110(%rsp), %xmm0
movsd %xmm0, 0xa0(%rsp)
movsd 0x98(%rsp), %xmm0
addsd 0x108(%rsp), %xmm0
movsd %xmm0, 0x98(%rsp)
movsd 0x80(%rsp), %xmm0
addsd 0x100(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x78(%rsp), %xmm0
addsd 0xf8(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x88(%rsp), %xmm0
addsd 0xf0(%rsp), %xmm0
movsd %xmm0, 0x88(%rsp)
movsd 0x70(%rsp), %xmm0
addsd 0xe8(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
callq 0x8104
leaq 0x128(%rsp), %rdi
callq 0x8104
movq %rbx, %rdi
callq 0x2dea
leaq 0x138(%rsp), %rdi
callq 0x2dea
movq %rbp, %rdi
callq 0x2dea
leaq 0xc0(%rsp), %rdi
callq 0x8104
movl 0xb8(%rsp), %eax
incl %eax
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
jmp 0x24aa
leaq 0x158(%rsp), %r14
movq %r14, %rdi
leaq 0x65b6(%rip), %rsi      # 0x904a
pushq $0x1
popq %rdx
callq 0x2040
leaq 0x658d(%rip), %r15      # 0x9030
movsd 0xa8(%rsp), %xmm0
divsd 0x6574(%rip), %xmm0     # 0x9028
movq %r14, %rdi
callq 0x2180
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
movsd 0x90(%rsp), %xmm0
divsd 0x6550(%rip), %xmm0     # 0x9028
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
movsd 0x98(%rsp), %xmm0
divsd 0x652c(%rip), %xmm0     # 0x9028
movq %r14, %rdi
callq 0x2180
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
movsd 0xa0(%rsp), %xmm0
divsd 0x6508(%rip), %xmm0     # 0x9028
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
movsd 0x78(%rsp), %xmm0
divsd 0x64e7(%rip), %xmm0     # 0x9028
movq %r14, %rdi
callq 0x2180
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
movsd 0x80(%rsp), %xmm0
divsd 0x64c3(%rip), %xmm0     # 0x9028
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
movsd 0x88(%rsp), %xmm0
divsd 0x649f(%rip), %xmm0     # 0x9028
movq %r14, %rdi
callq 0x2180
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
movsd 0x70(%rsp), %xmm0
divsd 0x647e(%rip), %xmm0     # 0x9028
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
movsd 0x28(%rsp), %xmm0
divsd 0x645d(%rip), %xmm0     # 0x9028
movq %r14, %rdi
callq 0x2180
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
movsd 0x30(%rsp), %xmm0
divsd 0x643c(%rip), %xmm0     # 0x9028
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
movsd 0x60(%rsp), %xmm0
divsd 0x641b(%rip), %xmm0     # 0x9028
movq %r14, %rdi
callq 0x2180
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
movsd 0x20(%rsp), %xmm0
divsd 0x63fa(%rip), %xmm0     # 0x9028
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
movq %r15, %rsi
callq 0x2130
movq %r14, %rdi
callq 0x2080
movq %r14, %rdi
callq 0x20d0
movq %r14, %rdi
callq 0x2150
movl 0xb4(%rsp), %eax
incl %eax
jmp 0x23c7
leaq 0x158(%rsp), %rdi
callq 0x2160
pushq $0x1
popq %rax
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2cae
jmp 0x2ca9
jmp 0x2cae
jmp 0x2ca9
jmp 0x2ca9
jmp 0x2ca9
jmp 0x2cae
jmp 0x2cae
jmp 0x2ccb
jmp 0x2ca9
jmp 0x2cae
jmp 0x2ca9
jmp 0x2cae
jmp 0x2ca9
jmp 0x2cae
jmp 0x2cf7
movq %rax, %rbx
jmp 0x2cbb
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x8104
leaq 0x38(%rsp), %rdi
callq 0x8104
jmp 0x2cfa
jmp 0x2d09
jmp 0x2cd4
movq %rax, %rbx
jmp 0x2d40
jmp 0x2cd9
jmp 0x2cf2
movq %rax, %rbx
jmp 0x2d26
movq %rax, %rbx
jmp 0x2d33
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x8104
jmp 0x2d33
jmp 0x2d09
movq %rax, %rbx
jmp 0x2d19
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x8104
jmp 0x2d0c
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0x2dea
leaq 0x138(%rsp), %rdi
callq 0x2dea
leaq 0xd0(%rsp), %rdi
callq 0x2dea
leaq 0xc0(%rsp), %rdi
callq 0x8104
leaq 0x158(%rsp), %rdi
callq 0x2160
movq %rbx, %rdi
callq 0x21d0
nopl (%rax)