// File: suhasjains[P]AMR-Solver/src/poisson.cpp
// Function: amrsolver::jacobi(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void jacobi(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);
	}

	double global_res = 1.0;

	long int loop = 0;

	//iteration loop
	while(loop <250 ) {
	//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];
							//	std::cerr << f->name << std::endl;
	
				if( f->name == name ) {
					
					global_res = jacobi_for_field(*it, f, global_res);	

				}	
			}
		}

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

		loop++;

	}	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rsi, -0x78(%rbp)
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x4a50
movslq -0x4(%rbp), %rax
leaq 0xef2a(%rip), %rdi      # 0x262e0
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x12570
testb $0x1, %al
jne 0x173c8
jmp 0x173ff
movq 0xec21(%rip), %rdi      # 0x25ff0
leaq 0xa1c9(%rip), %rsi      # 0x2159f
callq 0x3240
movq %rax, %rdi
movl -0x4(%rbp), %esi
callq 0x3400
movq %rax, %rdi
movq 0xebd0(%rip), %rsi      # 0x25fc0
callq 0x3270
movl $0x1, %edi
callq 0x32e0
movsd 0x9c09(%rip), %xmm0     # 0x21010
movsd %xmm0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
cmpq $0xfa, -0x20(%rbp)
jge 0x175ab
movq -0x78(%rbp), %rsi
movq $0x0, -0x18(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x84(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x3120
movl -0x84(%rbp), %edi
movq -0x80(%rbp), %rsi
callq 0xd220
jmp 0x17455
leaq -0x40(%rbp), %rdi
callq 0x3180
movslq -0x4(%rbp), %rax
leaq 0xee77(%rip), %rdi      # 0x262e0
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x4490
movq %rax, -0x58(%rbp)
movslq -0x4(%rbp), %rax
leaq 0xee5c(%rip), %rdi      # 0x262e0
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x44c0
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x44f0
testb $0x1, %al
jne 0x174aa
jmp 0x1756b
movl $0x0, -0x64(%rbp)
movslq -0x64(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq 0xf1f5(%rip), %rdi      # 0x266b8
callq 0x5b00
movq %rax, %rcx
movq -0x90(%rbp), %rax
cmpq %rcx, %rax
jae 0x1755b
leaq -0x58(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
callq 0x6de0
movq -0x78(%rbp), %rsi
movq 0x10(%rax), %rax
movslq -0x64(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
addq $0x18, %rdi
callq 0xd110
testb $0x1, %al
jne 0x17513
jmp 0x1754b
leaq -0x58(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movq -0x70(%rbp), %rsi
movsd -0x18(%rbp), %xmm0
callq 0x175c0
movsd %xmm0, -0x18(%rbp)
jmp 0x1754b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3180
jmp 0x175b4
jmp 0x1754d
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x174b1
jmp 0x1755d
leaq -0x58(%rbp), %rdi
callq 0x4550
jmp 0x17494
movq 0xea5e(%rip), %rdi      # 0x25fd0
leaq 0x9ffb(%rip), %rsi      # 0x21574
callq 0x3240
movq %rax, %rdi
movsd -0x18(%rbp), %xmm0
callq 0x3480
movq %rax, %rdi
movq 0xea2b(%rip), %rsi      # 0x25fc0
callq 0x3270
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x17414
addq $0x90, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3420
nopl (%rax)