tengo un problema ya que en un programa de c que es wa-tor(peces y tiburones) a la hora de hacer un collapse(2) para mejorar mediciones de tiempos me dice que los bucles no estan perfectamente anidados, es sobre OMP. Me gustaria saber como podria poner estos bucles perfectamente anidados.
Tambien me ayudaria saber la diferencia entre un bucle perfectamente anidado y otro que no lo está, cualquier ejemplo es de ayuda. Dejo la parte del programa y una captura de la consola. Muchas gracias.
Remarco con <<<< las 3 partes de los bucles y el collapse (2)
[Imagen por consola] [![https://i.sstatic.net/nu3AQ.png][1]][1]
<<<<< //First loop
#ifdef _OPENMP
#pragma omp parallel for firstprivate(Rows, Cols, Ocean, SimIter, pNFishes, NiFBreed, pRandData, pRandRes, local_N_Fishes, local_N_Sharks) collapse(2)
#endif
for (int i=0; i<Rows; i = i + 3) {
// loop 1.1
for (int j=0; j<Cols; j = j + 3)
{
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==FISH)
//TODO Add pRandData and pRandRes parameters at the end
IterateFish(Ocean,Rows,Cols,i,j,SimIter,pNFishes,NiFBreed, pRandData, pRandRes, local_N_Fishes);
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==SHARK)
//TODO Add pRandData and pRandRes parameters at the end
IterateShark(Ocean,Rows,Cols,i,j,SimIter, pNFishes, pNSharks, NiSBreed, SiEnergy, SeFEnergy, pRandData, pRandRes, local_N_Fishes, local_N_Sharks);
}
// Loop 1.2
for (int j=1; j<Cols; j = j + 3)
{
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==FISH)
//TODO Add pRandData and pRandRes parameters at the end
IterateFish(Ocean,Rows,Cols,i,j,SimIter,pNFishes,NiFBreed, pRandData, pRandRes, local_N_Fishes);
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==SHARK)
//TODO Add pRandData and pRandRes parameters at the end
IterateShark(Ocean,Rows,Cols,i,j,SimIter, pNFishes, pNSharks, NiSBreed, SiEnergy, SeFEnergy, pRandData, pRandRes, local_N_Fishes, local_N_Sharks);
}
//Loop 1.3
for (int j=2; j<Cols; j = j + 3)
{
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==FISH)
//TODO Add pRandData and pRandRes parameters at the end
IterateFish(Ocean,Rows,Cols,i,j,SimIter,pNFishes,NiFBreed, pRandData, pRandRes, local_N_Fishes);
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==SHARK)
//TODO Add pRandData and pRandRes parameters at the end
IterateShark(Ocean,Rows,Cols,i,j,SimIter, pNFishes, pNSharks, NiSBreed, SiEnergy, SeFEnergy, pRandData, pRandRes, local_N_Fishes, local_N_Sharks);
}
} //End first loop
<<<<< //Second loop
#ifdef _OPENMP
#pragma omp parallel for firstprivate(Rows, Cols, Ocean, SimIter, pNFishes, NiFBreed, pRandData, pRandRes, local_N_Fishes, local_N_Sharks) collapse(2)
#endif
for (int i=1; i<Rows; i = i + 3) {
// loop 2.1
for (int j=0; j<Cols; j = j + 3)
{
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==FISH)
//TODO Add pRandData and pRandRes parameters at the end
IterateFish(Ocean,Rows,Cols,i,j,SimIter,pNFishes,NiFBreed, pRandData, pRandRes, local_N_Fishes);
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==SHARK)
//TODO Add pRandData and pRandRes parameters at the end
IterateShark(Ocean,Rows,Cols,i,j,SimIter, pNFishes, pNSharks, NiSBreed, SiEnergy, SeFEnergy, pRandData, pRandRes, local_N_Fishes, local_N_Sharks);
}
// Loop 2.2
for (int j=1; j<Cols; j = j + 3)
{
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==FISH)
//TODO Add pRandData and pRandRes parameters at the end
IterateFish(Ocean,Rows,Cols,i,j,SimIter,pNFishes,NiFBreed, pRandData, pRandRes, local_N_Fishes);
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==SHARK)
//TODO Add pRandData and pRandRes parameters at the end
IterateShark(Ocean,Rows,Cols,i,j,SimIter, pNFishes, pNSharks, NiSBreed, SiEnergy, SeFEnergy, pRandData, pRandRes, local_N_Fishes, local_N_Sharks);
}
//Loop 2.3
for (int j=2; j<Cols; j = j + 3)
{
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==FISH)
//TODO Add pRandData and pRandRes parameters at the end
IterateFish(Ocean,Rows,Cols,i,j,SimIter,pNFishes,NiFBreed, pRandData, pRandRes, local_N_Fishes);
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==SHARK)
//TODO Add pRandData and pRandRes parameters at the end
IterateShark(Ocean,Rows,Cols,i,j,SimIter, pNFishes, pNSharks, NiSBreed, SiEnergy, SeFEnergy, pRandData, pRandRes, local_N_Fishes, local_N_Sharks);
}
} //End second loop
<<<<<< //Third loop
#ifdef _OPENMP
#pragma omp parallel for firstprivate(Rows, Cols, Ocean, SimIter, pNFishes, NiFBreed, pRandData, pRandRes, local_N_Fishes, local_N_Sharks) collapse(2)
#endif
for (int i=2; i<Rows; i = i + 3) {
// loop 3.1
for (int j=0; j<Cols; j = j + 3)
{
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==FISH)
//TODO Add pRandData and pRandRes parameters at the end
IterateFish(Ocean,Rows,Cols,i,j,SimIter,pNFishes,NiFBreed, pRandData, pRandRes, local_N_Fishes);
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==SHARK)
//TODO Add pRandData and pRandRes parameters at the end
IterateShark(Ocean,Rows,Cols,i,j,SimIter, pNFishes, pNSharks, NiSBreed, SiEnergy, SeFEnergy, pRandData, pRandRes, local_N_Fishes, local_N_Sharks);
}
// Loop 3.2
for (int j=1; j<Cols; j = j + 3)
{
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==FISH)
//TODO Add pRandData and pRandRes parameters at the end
IterateFish(Ocean,Rows,Cols,i,j,SimIter,pNFishes,NiFBreed, pRandData, pRandRes, local_N_Fishes);
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==SHARK)
//TODO Add pRandData and pRandRes parameters at the end
IterateShark(Ocean,Rows,Cols,i,j,SimIter, pNFishes, pNSharks, NiSBreed, SiEnergy, SeFEnergy, pRandData, pRandRes, local_N_Fishes, local_N_Sharks);
}
//Loop 3.3
for (int j=2; j<Cols; j = j + 3)
{
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==FISH)
//TODO Add pRandData and pRandRes parameters at the end
IterateFish(Ocean,Rows,Cols,i,j,SimIter,pNFishes,NiFBreed, pRandData, pRandRes, local_N_Fishes);
if (Ocean[i][j]!=NULL && Ocean[i][j]->Animal==SHARK)
//TODO Add pRandData and pRandRes parameters at the end
IterateShark(Ocean,Rows,Cols,i,j,SimIter, pNFishes, pNSharks, NiSBreed, SiEnergy, SeFEnergy, pRandData, pRandRes, local_N_Fishes, local_N_Sharks);
}
} //End third loop