1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
int k, i, j, l, numOfThreads ;
numOfThreads = 10;
// m = number of animals with genotypes;
// n = total number of animals
// Ped = matrix(n,2); Ped(i,1) = father; Ped(i,2) = mother
// Rhs = vector of size n having all zeroes and 1 for the animal of interest
// indx1(m) = vector containing all genotyped animals
// Sol(n) = vector containing interim solutions
// v(n) = vector containing final values of the matrix
// Asub(m,m) = matrix containg values for the genotyped animals
// all vectors and matrices are Blitz arrays
#pragma omp parallel private(i, j, k) shared(m,n,Ped,D,indx1, Sol, Rhs, Asub,v)
#pragma omp parallel for num_threads(numOfThreads)
{
for (k = 0; k < m; k++) { // this is the main loop
Rhs = 0.0;
Rhs(indx1(k)) = 1.0;
Sol = 0.0;
for (i = n-1; i > -1; i--) { // this is the second loop wwhere we add values to the relatives
Sol(i) += Rhs(i);
if (Ped(i,1) > 0) { // check for father
Sol(Ped(i,1)) += Sol(i)*0.5;
}
if (Ped(i,2) > 0) { // check for mother
Sol(Ped(i,2)) += Sol(i)*0.5;
}
}
v = 0.0;
for (j = 0; j < n; j++) { // this is the third loop; we calculate the values of the matrix
if (Ped(j,1) == 0 and Ped(j,2) == 0) {
v(j) = D(j)*Sol(j);
}
if (Ped(j,1) > 0 and Ped(j,2) > 0) {
v(j) = D(j)*Sol(j) + (v(Ped(j,1)) + v(Ped(j,2)))*0.5;
}
if (Ped(j,1) > 0 and Ped(j,2) == 0) {
v(j) = D(j)*Sol(j) + (v(Ped(j,1)))*0.5;
}
if (Ped(j,1) == 0 and Ped(j,2) > 0) {
v(j) = D(j)*Sol(j) + (v(Ped(j,2)))*0.5;
}
}
for (l = 0; l < m; l++) { // final loop where we put the values only for genotyped animals
Asub(k, l) = v(indx1(l));
}
} // end of k loop
} // end of OMP
|