我正在尝试实现Hogwild!线性 SVM算法,但我的实现遇到了错误的共享问题。
我的代码在下面,但背景是我正在尝试计算哪些样本未能通过我的测试并制作和更新由该组向量给出的。野猪!(据我了解)只是完全异步地对同一内存进行更新。由于不正确的时间更新,这将在数学意义上产生“噪音”。
可悲的是,当我尝试进行这些异步更新时,L1 缓存已失效并且必须重新获取。下面是我的代码。
有没有一种在不丢失异步的情况下修复这种错误共享的好方法?(我更像是一名数学家,而不是计算机科学家)。这提到使用不同的优化级别可以解决这个问题。
void update(size_t epoch, const double *X_data, const int *X_indices,
const int *X_indptr, const int *Y, double *W,
double reg, double step_size, size_t nodes,
size_t X_height, size_t X_width) {
size_t i, j;
double step = step_size/(1 + epoch);
double c;
#pragma omp parallel shared(W, X_data, X_indices, X_indptr, Y) private(i, j, c)
{
#pragma for schedule(static)
for (i=0;i<X_height;i++) {
c = 0.0;
for (j=X_indptr[i];j<X_indptr[i+1];j++)
c += X_data[j]*W[X_indices[j]]; // Scaled to discount the MPI scaling
if (Y[i]*c > 1)
continue;
for (j=X_indptr[i];j<X_indptr[i+1];j++)
W[X_indices[j]] += step*Y[i]*X_data[j]/(X_height*nodes);
} // END FOR OMP PARALLELIZED
#pragma for schedule(static) // Might not do much
for (i=0;i<X_width;i++) // (1 - self.reg*step)*self.W/self.nodes +
W[i] *= (1 - reg*step)/nodes;
}
}