0

I am trying to use STXXL to build a large matrix and be able to perform several different operations on the matrix. Currently, I'm using stxxl::vector as a way of storing submatrices of my large matrix. What I'm attempting to do is to normalize each column of the matrix. So my only data dependency should be in the columns. When I try to use openmp to parallelize the access to the submatrices I get the error message

[STXXL-ERRMSG] WRITE request submitted for a BID with a pending READ request

over and over again. Am I misunderstanding something on the thread-safety of STXXL? Because what I'm doing shouldn't ever be accessing the same submatrix. Here's the example code I'm trying to debug and run:

#include <iostream>
#include <stxxl/vector>

#define FEATURE_LENGTH 128
#define PARTITION_SIZE 16

typedef stxxl::VECTOR_GENERATOR<int>::result vec;

using namespace std;

struct MyMatrix
{
    float A[FEATURE_LENGTH*PARTITION_SIZE];
};

int main()
{
    const int N = (1 << 20);
    stxxl::vector<MyMatrix> C;
    for (int n = 0; n < N; ++n) {
        MyMatrix A;
        for (size_t j = 0; j < PARTITION_SIZE; ++j) {
            for (size_t i = 0; i < FEATURE_LENGTH; ++i) {
                A.A[j*FEATURE_LENGTH + i] = n;
            }
        }
        if (n == 0) {
            std::cout << "sizeof(A) = " << sizeof(A) << std::endl;
        }
        C.push_back(A);
    }

    #pragma omp parallel for shared(C)
    for (unsigned long long m = 0; m < C.size(); ++m) {
        for (int j = 0; j < PARTITION_SIZE; ++j) {
            MyMatrix& C_m = C[m];
            float sum = 0;
            for (int i = 0; i < FEATURE_LENGTH; ++i) {
                sum += C_m.A[j*FEATURE_LENGTH + i];
            }
            if (sum != 0) {
                for (int i = 0; i < FEATURE_LENGTH; ++i) {
                    C_m.A[j*FEATURE_LENGTH + i] /= sum;
                }
            }
        }
    }
    return 0;
}

The CXX flags I'm running are

-fopenmp -W -Wall -std=c++11 -O3

mculp
  • 59
  • 1
  • 7

1 Answers1

1

Access to the same vector is not thread-safe. Think about what the vector does: it's an elaborate paging system, and that is not thread-safe.

Timo Bingmann
  • 294
  • 1
  • 4
  • Alright, how exactly is the paging system not thread-safe. I'm assuming my interpretation of the thread-safety of the block managers is incorrect from . This answers my question, but it still doesn't really help me in understanding. – mculp Mar 12 '15 at 17:46