// File: /workspace/github_cpp_makefile_star2_O1/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 0x21b0
movl $0xf, %eax
leaq 0x7c47(%rip), %r15      # 0xa030
leaq 0x138(%rsp), %r13
leaq 0x148(%rsp), %rbp
movl %eax, 0xb4(%rsp)
cvtsi2sd %eax, %xmm1
movsd 0x7bfc(%rip), %xmm0     # 0xa008
callq 0x21e0
addsd 0x7bf7(%rip), %xmm0     # 0xa010
cvttsd2si %xmm0, %esi
movq %r14, %rdi
movq %rsi, 0x20(%rsp)
callq 0x21d0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movq 0x20(%rsp), %r15
leal -0x1(%r15), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x7bc2(%rip), %xmm1     # 0xa018
divsd %xmm0, %xmm1
movsd %xmm1, 0x120(%rsp)
negl %r15d
xorpd %xmm1, %xmm1
xorl %r12d, %r12d
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
xorps %xmm4, %xmm4
xorpd %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd %xmm0, 0x60(%rsp)
movsd %xmm0, 0x58(%rsp)
movsd %xmm0, 0x78(%rsp)
movsd %xmm0, 0x70(%rsp)
movsd %xmm0, 0x68(%rsp)
movsd %xmm0, 0x88(%rsp)
movsd %xmm0, 0x80(%rsp)
movsd %xmm4, 0xd8(%rsp)
movsd %xmm3, 0x48(%rsp)
movsd %xmm2, 0xc8(%rsp)
movsd %xmm1, 0xd0(%rsp)
callq 0x20c0
movq %rax, 0x18(%rsp)
movq %r13, %rdi
movq 0x20(%rsp), %rsi
callq 0x8268
leaq 0xb8(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x8f05
movq %r13, %rdi
movq %rbx, %rsi
callq 0x89dc
movq %rbx, %rdi
callq 0x8310
movq %rbx, %rdi
movq 0x20(%rsp), %rdx
movl %edx, %esi
callq 0x2eb8
leaq 0x128(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3ee1
movq %rbx, %rdi
movq %r14, %rsi
callq 0x35a0
movq %r14, %rdi
callq 0x2f4c
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3140
movq %rbp, %rdi
movq 0x20(%rsp), %rdx
movl %edx, %esi
callq 0x2eb8
movq %rbp, %rdi
leaq 0xb8(%rsp), %rsi
callq 0x35a0
movl %r12d, 0x28(%rsp)
movq %r13, %rbx
movq 0x20(%rsp), %r13
testl %r13d, %r13d
jle 0x25f3
movl $0x1, %r14d
xorps %xmm0, %xmm0
cvtsi2ss %r14d, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x120(%rsp), %xmm0
addsd 0x7a76(%rip), %xmm0     # 0xa018
movsd %xmm0, 0x10(%rsp)
movl $0x1, %r12d
movq %rbp, %rdi
movl %r14d, %esi
movl %r12d, %edx
callq 0x2f92
movsd (%rax), %xmm0
mulsd 0x10(%rsp), %xmm0
movq %rbp, %rdi
movl %r14d, %esi
movl %r12d, %edx
callq 0x392c
leal (%r15,%r12), %eax
incl %eax
movl %r12d, %ecx
incl %ecx
movl %ecx, %r12d
cmpl $0x1, %eax
jne 0x25ae
leal 0x1(%r14), %eax
cmpl %r13d, %r14d
movl %eax, %r14d
jne 0x2585
leaq 0xa0(%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x3941
callq 0x20c0
subq 0x18(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x7a00(%rip), %xmm0     # 0xa020
movsd %xmm0, 0x10(%rsp)
movl $0x6, %edx
movq 0xb99e(%rip), %rbx      # 0xdfd0
movq %rbx, %rdi
leaq 0x79f6(%rip), %rsi      # 0xa032
callq 0x2160
movq %rbx, %rdi
movl %r13d, %esi
callq 0x21d0
movq %rax, %rbx
movl $0x10, %edx
movq %rax, %rdi
leaq 0x79db(%rip), %rsi      # 0xa039
callq 0x2160
movq %rbx, %rdi
movsd 0x10(%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, 0xc(%rsp)
callq 0x20c0
movq %rax, %rbx
movl %r14d, 0xc(%rsp)
leaq 0x90(%rsp), %rdi
movq %rbp, %rsi
leaq 0xa0(%rsp), %r14
movq %r14, %rdx
leaq 0xc(%rsp), %r13
movq %r13, %rcx
callq 0x7172
callq 0x20c0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x7935(%rip), %xmm0     # 0xa020
movsd %xmm0, 0x118(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0xc(%rsp), %xmm0
movsd %xmm0, 0x110(%rsp)
callq 0x20c0
movq %rax, %rbx
movl $0x0, 0xc(%rsp)
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x740c
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
callq 0x89dc
movq %r12, %rdi
callq 0x8310
callq 0x20c0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x78c4(%rip), %xmm0     # 0xa020
movsd %xmm0, 0x108(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0xc(%rsp), %xmm0
movsd %xmm0, 0x100(%rsp)
callq 0x20c0
movq %rax, %rbx
movl $0x0, 0xc(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
leaq 0xa0(%rsp), %rdx
leaq 0xc(%rsp), %rcx
callq 0x78ed
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
callq 0x89dc
movq %r12, %rdi
callq 0x8310
callq 0x20c0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x7851(%rip), %xmm0     # 0xa020
movsd %xmm0, 0xf8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0xc(%rsp), %xmm0
movsd %xmm0, 0xf0(%rsp)
callq 0x20c0
movq %rax, %rbx
movq %r12, %rdi
movq %rbp, %rsi
leaq 0xa0(%rsp), %rdx
callq 0x494e
leaq 0x90(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x89dc
movq %r12, %rdi
callq 0x8310
callq 0x20c0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x77e8(%rip), %xmm0     # 0xa020
movsd %xmm0, 0xe8(%rsp)
movq %r12, %rdi
movq %r14, %rsi
leaq 0x138(%rsp), %r13
movq %r13, %rdx
callq 0x84c8
movq %r12, %rdi
movl $0x2, %esi
callq 0x8dfc
movsd %xmm0, 0xe0(%rsp)
movq %r12, %rdi
callq 0x8310
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd %xmm0, 0x18(%rsp)
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %rax
cmpl $0xc7, %eax
jg 0x2944
callq 0x20c0
movq %rax, %rbx
movq %r12, %rdi
movq %rbp, %rsi
leaq 0xa0(%rsp), %rdx
callq 0x56d0
leaq 0x90(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x89dc
movq %r12, %rdi
callq 0x8310
callq 0x20c0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x7737(%rip), %xmm0     # 0xa020
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x84c8
movq %r12, %rdi
movl $0x2, %esi
callq 0x8dfc
movq %r12, %rdi
movsd %xmm0, 0x18(%rsp)
callq 0x8310
movsd 0xd8(%rsp), %xmm1
addsd 0x10(%rsp), %xmm1
movsd 0x48(%rsp), %xmm0
addsd 0x18(%rsp), %xmm0
movsd %xmm1, 0x18(%rsp)
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %rax
xorpd %xmm0, %xmm0
cmpl $0x63, %eax
movl 0x28(%rsp), %ebx
jg 0x29fa
callq 0x20c0
movq %rax, %rbx
movq %r12, %rdi
movq %rbp, %rsi
leaq 0xa0(%rsp), %rdx
callq 0x4d51
leaq 0x90(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x89dc
movq %r12, %rdi
callq 0x8310
callq 0x20c0
subq %rbx, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x767d(%rip), %xmm0     # 0xa020
movsd %xmm0, 0x30(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x84c8
movq %r12, %rdi
movl $0x2, %esi
callq 0x8dfc
movq %r12, %rdi
movsd %xmm0, 0x48(%rsp)
callq 0x8310
movsd 0xc8(%rsp), %xmm1
addsd 0x30(%rsp), %xmm1
movsd 0xd0(%rsp), %xmm0
addsd 0x48(%rsp), %xmm0
movsd %xmm1, 0x30(%rsp)
movl 0x28(%rsp), %ebx
movsd %xmm0, 0x28(%rsp)
movsd 0x88(%rsp), %xmm0
addsd 0x118(%rsp), %xmm0
movsd %xmm0, 0x88(%rsp)
movsd 0x80(%rsp), %xmm0
addsd 0x110(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x70(%rsp), %xmm0
addsd 0x108(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0x68(%rsp), %xmm0
addsd 0x100(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x58(%rsp), %xmm0
addsd 0xf8(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x78(%rsp), %xmm0
addsd 0xf0(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x60(%rsp), %xmm0
addsd 0xe8(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x50(%rsp), %xmm0
addsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x8310
leaq 0xa0(%rsp), %rdi
callq 0x8310
movq %rbp, %rdi
callq 0x2f4c
leaq 0x128(%rsp), %rdi
callq 0x2f4c
leaq 0xb8(%rsp), %rdi
callq 0x2f4c
movq %r13, %rdi
callq 0x8310
movsd 0x28(%rsp), %xmm1
incl %ebx
movsd 0x30(%rsp), %xmm2
movsd 0x10(%rsp), %xmm3
movsd 0x18(%rsp), %xmm4
cmpl $0xb, %ebx
movl %ebx, %r12d
jne 0x24b0
leaq 0x158(%rsp), %r14
movq %r14, %rdi
leaq 0x751a(%rip), %rsi      # 0xa04a
movl $0x1, %edx
callq 0x2050
leaq 0x74ef(%rip), %r15      # 0xa030
movsd 0x80(%rsp), %xmm0
divsd 0x74d6(%rip), %xmm0     # 0xa028
movq %r14, %rdi
callq 0x21a0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x88(%rsp), %xmm0
divsd 0x74aa(%rip), %xmm0     # 0xa028
movq %rbx, %rdi
callq 0x21a0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x68(%rsp), %xmm0
divsd 0x7484(%rip), %xmm0     # 0xa028
movq %r14, %rdi
callq 0x21a0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x70(%rsp), %xmm0
divsd 0x745b(%rip), %xmm0     # 0xa028
movq %rbx, %rdi
callq 0x21a0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x78(%rsp), %xmm0
divsd 0x7435(%rip), %xmm0     # 0xa028
movq %r14, %rdi
callq 0x21a0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x58(%rsp), %xmm0
divsd 0x740c(%rip), %xmm0     # 0xa028
movq %rbx, %rdi
callq 0x21a0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x60(%rsp), %xmm0
divsd 0x73e6(%rip), %xmm0     # 0xa028
movq %r14, %rdi
callq 0x21a0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x50(%rsp), %xmm0
divsd 0x73bd(%rip), %xmm0     # 0xa028
movq %rbx, %rdi
callq 0x21a0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x18(%rsp), %xmm0
divsd 0x7397(%rip), %xmm0     # 0xa028
movq %r14, %rdi
callq 0x21a0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x10(%rsp), %xmm0
divsd 0x736e(%rip), %xmm0     # 0xa028
movq %rbx, %rdi
callq 0x21a0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x30(%rsp), %xmm0
divsd 0x7348(%rip), %xmm0     # 0xa028
movq %r14, %rdi
callq 0x21a0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movsd 0x28(%rsp), %xmm0
divsd 0x731f(%rip), %xmm0     # 0xa028
movq %rbx, %rdi
callq 0x21a0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2160
movq 0x158(%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 0xb4(%rsp), %eax
incl %eax
cmpl $0x33, %eax
jne 0x23f9
movq 0xb252(%rip), %rax      # 0xdfc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x160(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x158(%rsp,%rcx)
callq 0x2120
leaq 0x250(%rsp), %rdi
callq 0x2070
movl $0x1, %eax
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2dda
jmp 0x2dda
jmp 0x2dda
jmp 0x2dda
jmp 0x2deb
jmp 0x2deb
jmp 0x2deb
jmp 0x2deb
jmp 0x2dda
jmp 0x2dda
jmp 0x2deb
jmp 0x2deb
jmp 0x2dda
jmp 0x2deb
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x8310
jmp 0x2dee
jmp 0x2e41
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x8310
jmp 0x2e32
jmp 0x2e2f
jmp 0x2e03
jmp 0x2e0a
movq %rax, %rbx
jmp 0x2e5e
jmp 0x2e2a
movq %rax, %rbx
jmp 0x2e51
jmp 0x2e25
jmp 0x2e41
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x8310
jmp 0x2e6b
movq %rax, %rbx
jmp 0x2e6b
movq %rax, %rbx
jmp 0x2e78
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x8310
jmp 0x2e44
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0x2f4c
leaq 0x128(%rsp), %rdi
callq 0x2f4c
leaq 0xb8(%rsp), %rdi
callq 0x2f4c
leaq 0x138(%rsp), %rdi
callq 0x8310
movq 0xb149(%rip), %rax      # 0xdfc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x160(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x158(%rsp,%rcx)
callq 0x2120
leaq 0x250(%rsp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x21f0