// File: /workspace/github_cpp_makefile_star2_O1/suhasjains[P]AMR-Solver/src/poisson.cpp
// Function: amrsolver::gauss_seidel(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void gauss_seidel(int level, std::string name) {

	myOctree::create_lists_of_level_nodes();

	if(myOctree::level_nodes[level].empty()) {
        	std::cerr << "No blocks in level " << level << std::endl;
	 	exit(1);
	}

	std::cerr << "Solving" << std::endl;

	double global_res = 1.0;

	long int loop = 0;

	//iteration loop
	while(loop <200 ) {
	//while(global_res > pow(10,-7)) {

		global_res = 0.0;
		
		//exchange ghost values
		exchange_ghost_val(level, name);

		//loop over all the nodes
		for (std::list<Octree*>::iterator it = level_nodes[level].begin(), end = level_nodes[level].end(); it != end; ++it) {
	
			for(int l = 0; l<myOctree::scalar_fields.size() ; l++) {
	
				Field *f = (*it)->get_block_data()->scalarfields[l];
				if( f->name == name ) {
					
					global_res = gauss_seidel_red(*it, f, global_res);	

				}	
			}
		}

		//exchange ghost values
		exchange_ghost_val(level, name);
		
		//loop over all the nodes
		for (std::list<Octree*>::iterator it = level_nodes[level].begin(), end = level_nodes[level].end(); it != end; ++it) {
	
			for(int l = 0; l<myOctree::scalar_fields.size() ; l++) {
	
				Field *f = (*it)->get_block_data()->scalarfields[l];
				if( f->name == name ) {
					
					global_res = gauss_seidel_black(*it, f, global_res);	

				}	
			}
		}

		std::cout << "Residual " << global_res << std::endl; 

		loop++;

	}	
		std::cout << "Residual " << global_res << std::endl; 
		std::cout << "No of loops " << loop << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r14
movl %edi, %ebx
callq 0x3010
movl %ebx, -0x34(%rbp)
movslq %ebx, %rax
leaq (%rax,%rax,2), %rax
leaq 0x7362(%rip), %rcx      # 0x15250
leaq (%rcx,%rax,8), %rax
movq %rax, -0x40(%rbp)
cmpq %rax, (%rax)
je 0xe205
movq 0x70ea(%rip), %r15      # 0x14ff0
leaq 0x36bd(%rip), %rsi      # 0x115ca
movl $0x7, %edx
movq %r15, %rdi
callq 0x2230
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq -0x60(%rbp), %r15
xorl %ebx, %ebx
leaq 0x76da(%rip), %r13      # 0x15628
movq %r15, -0x48(%rbp)
movq %r15, -0x70(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %r12
movq %r12, %rdi
callq 0x391e
movl -0x34(%rbp), %edi
movq %r12, %rsi
callq 0x7394
movq %rbx, -0x50(%rbp)
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0xdf90
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x40(%rbp), %rax
movq (%rax), %rbx
xorps %xmm0, %xmm0
cmpq %rax, %rbx
je 0xe016
movq 0x8(%r13), %rax
cmpq (%r13), %rax
je 0xe00d
xorl %r12d, %r12d
movsd %xmm0, -0x30(%rbp)
movq 0x10(%rbx), %rdi
callq 0x4064
movq 0x10(%rax), %rax
movq (%rax,%r12,8), %r15
movq 0x20(%r15), %rdx
cmpq 0x8(%r14), %rdx
jne 0xdfe1
testq %rdx, %rdx
je 0xdfe8
movq (%r14), %rsi
movq 0x18(%r15), %rdi
callq 0x2210
testl %eax, %eax
je 0xdfe8
movsd -0x30(%rbp), %xmm0
jmp 0xdff9
movq 0x10(%rbx), %rdi
movq %r15, %rsi
movsd -0x30(%rbp), %xmm0
callq 0xe268
incq %r12
movq 0x8(%r13), %rax
subq (%r13), %rax
sarq $0x5, %rax
cmpq %r12, %rax
ja 0xdfac
movq (%rbx), %rbx
cmpq -0x40(%rbp), %rbx
jne 0xdf9f
movsd %xmm0, -0x30(%rbp)
leaq -0x80(%rbp), %r15
movq %r15, -0x90(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %rbx
movq %rbx, %rdi
callq 0x391e
movl -0x34(%rbp), %edi
movq %rbx, %rsi
callq 0x7394
movq -0x90(%rbp), %rdi
cmpq %r15, %rdi
je 0xe062
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x40(%rbp), %rax
movq (%rax), %rbx
cmpq %rax, %rbx
movsd -0x30(%rbp), %xmm0
je 0xe0ea
movq 0x8(%r13), %rax
cmpq (%r13), %rax
je 0xe0e1
xorl %r12d, %r12d
movsd %xmm0, -0x30(%rbp)
movq 0x10(%rbx), %rdi
callq 0x4064
movq 0x10(%rax), %rax
movq (%rax,%r12,8), %r15
movq 0x20(%r15), %rdx
cmpq 0x8(%r14), %rdx
jne 0xe0b5
testq %rdx, %rdx
je 0xe0bc
movq (%r14), %rsi
movq 0x18(%r15), %rdi
callq 0x2210
testl %eax, %eax
je 0xe0bc
movsd -0x30(%rbp), %xmm0
jmp 0xe0cd
movq 0x10(%rbx), %rdi
movq %r15, %rsi
movsd -0x30(%rbp), %xmm0
callq 0xe6c5
incq %r12
movq 0x8(%r13), %rax
subq (%r13), %rax
sarq $0x5, %rax
cmpq %r12, %rax
ja 0xe080
movq (%rbx), %rbx
cmpq -0x40(%rbp), %rbx
jne 0xe073
movsd %xmm0, -0x30(%rbp)
movl $0x9, %edx
movq 0x6ed5(%rip), %rbx      # 0x14fd0
movq %rbx, %rdi
leaq 0x34bb(%rip), %rsi      # 0x115c0
callq 0x2230
movq %rbx, %rdi
movsd -0x30(%rbp), %xmm0
callq 0x2300
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq -0x50(%rbp), %rbx
incq %rbx
cmpq $0xc8, %rbx
leaq -0x60(%rbp), %r15
jne 0xdf52
movq 0x6e70(%rip), %rbx      # 0x14fd0
leaq 0x3459(%rip), %rsi      # 0x115c0
movl $0x9, %edx
movq %rbx, %rdi
callq 0x2230
movq %rbx, %rdi
movsd -0x30(%rbp), %xmm0
callq 0x2300
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq 0x3420(%rip), %rsi      # 0x115d2
movl $0xc, %edx
movq %rbx, %rdi
callq 0x2230
movl $0xc8, %esi
movq %rbx, %rdi
callq 0x21c0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x6de4(%rip), %rdi      # 0x14ff0
leaq 0x33d8(%rip), %rsi      # 0x115eb
callq 0x21e0
movq %rax, %rdi
movl -0x34(%rbp), %esi
callq 0x2330
movq %rax, %rdi
callq 0x2100
movl $0x1, %edi
callq 0x2250
movq %rax, %rbx
movq -0x90(%rbp), %rdi
movq %r15, -0x48(%rbp)
jmp 0xe24c
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0xe260
movq -0x48(%rbp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2340