// File: /workspace/github_cpp_makefile_star2_O3/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 0x3018
movl %ebx, -0x34(%rbp)
movslq %ebx, %rax
leaq (%rax,%rax,2), %rax
leaq 0x7356(%rip), %rcx      # 0x15260
leaq (%rcx,%rax,8), %rax
movq %rax, -0x40(%rbp)
cmpq %rax, (%rax)
je 0xe251
movq 0x70ce(%rip), %r15      # 0x14ff0
leaq 0x36d1(%rip), %rsi      # 0x115fa
movl $0x7, %edx
movq %r15, %rdi
callq 0x2240
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2160
leaq -0x60(%rbp), %r15
xorl %ebx, %ebx
leaq 0x76ce(%rip), %r13      # 0x15638
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 0x39ba
movl -0x34(%rbp), %edi
movq %r12, %rsi
callq 0x744c
movq %rbx, -0x50(%rbp)
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0xdfac
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x40(%rbp), %rax
movq (%rax), %rbx
cmpq %rax, %rbx
je 0xe046
movq (%r13), %rax
movq 0x8(%r13), %rcx
xorps %xmm0, %xmm0
cmpq %rax, %rcx
je 0xe038
xorl %r12d, %r12d
movsd %xmm0, -0x30(%rbp)
movq 0x10(%rbx), %rdi
callq 0x418c
movq 0x10(%rax), %rax
movq (%rax,%r12,8), %r15
movq 0x20(%r15), %rdx
cmpq 0x8(%r14), %rdx
jne 0xe004
testq %rdx, %rdx
je 0xe00b
movq (%r14), %rsi
movq 0x18(%r15), %rdi
callq 0x2220
testl %eax, %eax
je 0xe00b
movsd -0x30(%rbp), %xmm0
jmp 0xe01c
movq 0x10(%rbx), %rdi
movq %r15, %rsi
movsd -0x30(%rbp), %xmm0
callq 0xe2b4
incq %r12
movq (%r13), %rax
movq 0x8(%r13), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r12, %rdx
ja 0xdfcf
jmp 0xe03b
movq %rax, %rcx
movq (%rbx), %rbx
cmpq -0x40(%rbp), %rbx
jne 0xdfc7
jmp 0xe049
xorps %xmm0, %xmm0
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 0x39ba
movl -0x34(%rbp), %edi
movq %rbx, %rsi
callq 0x744c
movq -0x90(%rbp), %rdi
cmpq %r15, %rdi
je 0xe095
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x40(%rbp), %rax
movq (%rax), %rbx
cmpq %rax, %rbx
je 0xe131
movq (%r13), %rax
movq 0x8(%r13), %rcx
movsd -0x30(%rbp), %xmm0
cmpq %rax, %rcx
je 0xe123
xorl %r12d, %r12d
movsd %xmm0, -0x30(%rbp)
movq 0x10(%rbx), %rdi
callq 0x418c
movq 0x10(%rax), %rax
movq (%rax,%r12,8), %r15
movq 0x20(%r15), %rdx
cmpq 0x8(%r14), %rdx
jne 0xe0ef
testq %rdx, %rdx
je 0xe0f6
movq (%r14), %rsi
movq 0x18(%r15), %rdi
callq 0x2220
testl %eax, %eax
je 0xe0f6
movsd -0x30(%rbp), %xmm0
jmp 0xe107
movq 0x10(%rbx), %rdi
movq %r15, %rsi
movsd -0x30(%rbp), %xmm0
callq 0xe6f2
incq %r12
movq (%r13), %rax
movq 0x8(%r13), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r12, %rdx
ja 0xe0ba
jmp 0xe126
movq %rax, %rcx
movq (%rbx), %rbx
cmpq -0x40(%rbp), %rbx
jne 0xe0b2
jmp 0xe136
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0x9, %edx
movq 0x6e89(%rip), %rbx      # 0x14fd0
movq %rbx, %rdi
leaq 0x349f(%rip), %rsi      # 0x115f0
callq 0x2240
movq %rbx, %rdi
movsd -0x30(%rbp), %xmm0
callq 0x2310
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2160
movq -0x50(%rbp), %rbx
incq %rbx
cmpq $0xc8, %rbx
leaq -0x60(%rbp), %r15
jne 0xdf6e
movq 0x6e24(%rip), %rbx      # 0x14fd0
leaq 0x343d(%rip), %rsi      # 0x115f0
movl $0x9, %edx
movq %rbx, %rdi
callq 0x2240
movq %rbx, %rdi
movsd -0x30(%rbp), %xmm0
callq 0x2310
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2160
leaq 0x3404(%rip), %rsi      # 0x11602
movl $0xc, %edx
movq %rbx, %rdi
callq 0x2240
movl $0xc8, %esi
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2160
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x6d98(%rip), %rdi      # 0x14ff0
leaq 0x33bc(%rip), %rsi      # 0x1161b
callq 0x21f0
movq %rax, %rdi
movl -0x34(%rbp), %esi
callq 0x2340
movq %rax, %rdi
callq 0x2100
movl $0x1, %edi
callq 0x2260
movq %rax, %rbx
movq -0x90(%rbp), %rdi
movq %r15, -0x48(%rbp)
jmp 0xe298
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0xe2ac
movq -0x48(%rbp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x2210
movq %rbx, %rdi
callq 0x2350