anchor.diff:        delta_s2 += delta_det(:,:,i,2)
       end do
     else
  -
  -  delta = cp(:,:,cur_cp,1)
  -  delta_s2 = cp(:,:,cur_cp,2)
  -  do i=cp_first_tooth(cur_cp)-1,0,-1
  -    delta += delta_det(:,:,i,1)
  -    delta_s2 += delta_det(:,:,i,2)
  -  end do
  -
  +    delta = cp(:,:,cur_cp,1)
  +    delta_s2 = cp(:,:,cur_cp,2)
  +    do i=cp_first_tooth(cur_cp)-1,0,-1
  +      delta += delta_det(:,:,i,1)
  +      delta_s2 += delta_det(:,:,i,2)
  +    end do
     end if
  -  mrcc(1) = E
  +  mrcc = E
     call end_zmq_to_qp_run_socket(zmq_to_qp_run_socket)
   end subroutine
   
  
positive.code:   actually_computed = .false.
  
    zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
    allocate(task_id(N_det_generators), ind(1))
    more = 1
    time = omp_get_wtime()
    time0 = time
    timeInit = time
    cur_cp = 0
    old_cur_cp = 0
    pullLoop : do while (more == 1)
      call pull_mrcc_results(zmq_socket_pull, Nindex, ind, mrcc_mwen, delta_loc, task_id, ntask)
      if(Nindex /= 1) stop "tried pull multiple Nindex"
  
      do i=1,Nindex
        mrcc_detail(:, ind(i)) += mrcc_mwen(:)
        do j=1,N_cp !! optimizable
          if(cps(ind(i), j) > 0d0) then
            if(tooth_of_det(ind(i)) < cp_first_tooth(j)) stop "coef on supposedely deterministic det"
            double precision :: fac
            integer :: toothMwen
            logical :: fracted
            fac = cps(ind(i), j) / cps_N(j) * mrcc_weight_inv(ind(i)) * comb_step
            do k=1,N_det_non_ref
            do i_state=1,N_states
              cp(i_state,k,j,1) += delta_loc(i_state,k,1) * fac
              cp(i_state,k,j,2) += delta_loc(i_state,k,2) * fac
            end do
            end do
          end if
        end do
        toothMwen = tooth_of_det(ind(i))
        fracted = (toothMwen /= 0)
        if(fracted) fracted = (ind(i) == first_det_of_teeth(toothMwen))
        
        if(fracted) then
          delta_det(:,:,toothMwen-1, 1) += delta_loc(:,:,1) * (1d0-fractage(toothMwen))
          delta_det(:,:,toothMwen-1, 2) += delta_loc(:,:,2) * (1d0-fractage(toothMwen))
          delta_det(:,:,toothMwen, 1) += delta_loc(:,:,1) * (fractage(toothMwen))
          delta_det(:,:,toothMwen, 2) += delta_loc(:,:,2) * (fractage(toothMwen))
        else
          delta_det(:,:,toothMwen, 1) += delta_loc(:,:,1)
          delta_det(:,:,toothMwen, 2) += delta_loc(:,:,2)
        end if
  
        parts_to_get(ind(i)) -= 1
        if(parts_to_get(ind(i)) == 0) then
          actually_computed(ind(i)) = .true.
          !print *, "CONTRIB", ind(i), psi_non_ref_coef(ind(i),1), mrcc_detail(1, ind(i))
          total_computed += 1
        end if
      end do
  
  
      integer, external :: zmq_delete_tasks
      if (zmq_delete_tasks(zmq_to_qp_run_socket,zmq_socket_pull,task_id,ntask,more) == -1) then
          stop 'Unable to delete tasks'
      endif
  
  
      time = omp_get_wtime()
      
      
  
      if(time - time0 > 10d0 .or. more /= 1) then
        time0 = time
        cur_cp = N_cp
        !if(.not. actually_computed(mrcc_jobs(1))) cycle pullLoop
  
  
negative.code:   cps(:, N_cp) = 0d0
    cp_first_tooth(N_cp) = comb_teeth+1
  
    !iorder = -1132154665
    !do i=1,N_cp-1
    !  call isort(mrcc_jobs(first_cp(i)+1:first_cp(i+1)),iorder,first_cp(i+1)-first_cp(i))
    !end do
  END_PROVIDER
  
  
  