【发布时间】:2014-03-11 16:16:56
【问题描述】:
我无法访问或打印嵌套 for 循环中的任何数据。这是我第一次编写 MPI 程序,所有的例子都没有比 Hello World 更复杂。我做错了什么?
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”还有很多示例。
-
我已经做了一个 hello world 并且在这种情况下没有帮助。简单的 MPI 程序无助于跳转到实际代码。让我开始的一点帮助会很好。我理解这些概念,我的第一个程序只需要一些帮助。
-
在不知道
azimuth、cluster、NUMOFSTARCOORD是如何被清除的情况下很难告诉你出了什么问题。这是MPI_Bcast()示例的链接:mpi.deino.net/mpi_functions/MPI_Bcast.html