我無法訪問或打印嵌套for循環中的任何數據。這是我第一次寫了一個MPI程序,所有例子都沒有顯示比Hello World更復雜的東西。我究竟做錯了什麼?無法在MPI中訪問嵌套for循環Bcast
void assignStarsToClusters(double *stars, double *clusters, int *azimuth)
{
ostringstream oss;
oss.str("");
oss.clear();
//double start = MPI_Wtime();
// Assign a star to the closest cluster
double smallDistance;
double tmpDistance;
int indice = 0;
MPI_Barrier(MPI_COMM_WORLD);
MPI_Bcast(azimuth /*the data we're broadcasting*/,
NUMOFLINES /*the data size */,
MPI_INT /*the data type */,
0 /*the process we're broadcasting from */,
MPI_COMM_WORLD);
MPI_Bcast(stars /*the data we're broadcasting*/,
NUMOFSTARCOORD /*the data size */,
MPI_DOUBLE /*the data type */,
0 /*the process we're broadcasting from */,
MPI_COMM_WORLD);
MPI_Bcast(clusters /*the data we're broadcasting*/,
NUMOFCLUST /*the data size */,
MPI_DOUBLE /*the data type */,
0 /*the process we're broadcasting from */,
MPI_COMM_WORLD);
MPI_Bcast(&NUMOFCLUST /*the data we're broadcasting*/,
1 /*the data size */,
MPI_DOUBLE /*the data type */,
0 /*the process we're broadcasting from */,
MPI_COMM_WORLD);
MPI_Bcast(&NUMOFSTARCOORD /*the data we're broadcasting*/,
1 /*the data size */,
MPI_DOUBLE /*the data type */,
0 /*the process we're broadcasting from */,
MPI_COMM_WORLD);
int sx = NUMOFSTARCOORD/comm_sz;
int s_lower = my_rank * sx;
int s_upper = s_lower + sx;
for(int a = my_rank; a <= comm_sz; a++)
{
for(int i = s_lower; i <= s_upper; i+=3)
{
smallDistance = sqrt(sqr(stars[i] - clusters[0]) + sqr(stars[i+1] - clusters[1]) + sqr(stars[i+2] - clusters[2]));
indice = 0;
for(int j = 3; j <= (NUMOFCLUST * 3); j+=3)
{
tmpDistance = sqrt(sqr(stars[i] - clusters[j]) + sqr(stars[i+1] - clusters[j+1]) + sqr(stars[i+2] - clusters[j+2]));
oss << " " << j;
if(tmpDistance < smallDistance)
{
smallDistance = tmpDistance;
indice = j;
}
}
azimuth[i/3] = indice/3;
//oss << " " << indice;
}
}
MPI_Barrier(MPI_COMM_WORLD);
// cout << oss.str() << endl;
//oss.str("");
//oss.clear();
//if(my_rank == 0)
//{
//for (int i = 0; i < NUMOFLINES; i++) {
// oss << " " << azimuth[i];
//}
//}
cout << oss.str() << endl;
//cout << "Total Time: " << MPI_Wtime() - start << endl;
}
你不能指望我們在SO教你MPI。只需搜索「MPI教程」,並從那裏開始:有更多的例子「hello world」。 – Sigismondo
我已經做了一個你好的世界,並沒有幫助在這種情況下。簡單的MPI程序不會幫助您跳轉到真正的代碼。有一點幫助讓我開始會很好。我理解這些概念,我只需要我的第一個程序的一些幫助。 – SINGULARITY
如果不知道'azimuth','cluster','NUMOFSTARCOORD'是否被刪除,那麼很難告訴你什麼是錯誤的。下面是一個MPI_Bcast()的例子:http://mpi.deino.net/mpi_functions/MPI_Bcast.html – francis