Parallel for loop givings the wrong output

I'm trying to parallel a nested for loop using the foreach package. However, while the speed is much faster, it doesn't give the correct answer. The idea of this particular nested for loop is quite straightforward. The result (a number) of the most inside nested loop is added to the second layer loop, which is added to the third layer loop. Below is a reproducible data:

input <- data.frame(matrix(rnorm(100*100, 1, .5), ncol=100))
input[input <0] =0

d = 0
n = 0
j = 1
k = 1
f = 0
s = 0
cl <- parallel::makeCluster(18)
doParallel::registerDoParallel(cl)
tm1 <- system.time(


  foreach (j = (1:nrow(input)), .combine = c,.packages = 'foreach') %dopar%{
    for (k  in (1:nrow(input))){
      if (k != j) {

        for (i in (2:nrow(input))){

          n = n + (input[j,i] * input[k, i])
          d = d + input[j, i] * input[j, i]


        }
        f = f + n/d * input[k, 1]

      }


      n = 0
      d = 0
    }

    s = s + f * input[j,2]

    k = 1
    f = 0
  }

)
parallel::stopCluster(cl)

The final output s is 0. However, if I use the regularly for loop without parallel, it returns 9597. Additionally, after running the foreach loop, I found only i to be 100 while k and j are 1 only, which seems wrong because I want k to be unequal to j at any time (as indicated in the code). I wonder why I am wrong in the code.