1 Reply Latest reply on Nov 10, 2016 7:32 AM by Intel Corporation

    Multithreading issues seen on dual chip machine with 2x E5-2650V3 processor

    sascham

      I see a multithreading issue on a dual chip machine with E5-2650V3 processors for the code below. This is associated with the malloc/free calls in the code below (also tried new / delete, creating std::vectors, using Windows HeapAlloc). Intel Vtune amplifier shows many cache misses for the code. The issue only occurs when the code is run after calling some other GUI related code and only on the specified machine type. Note that no other event loops or anything else is run by the previously called code when running the code below. It doesn't occur on a similar machine with two E5-2665 processors, where zero cache misses are reported. Question is whether this is a OS related issue (in this case Windows 7), or an issue with the GUI system (Qt 5.6.1). But if this is the case, why would it also be processor specific.

       

      std::vector<std::future<void>> futures;

           for (auto iii = 0; iii != 40; iii++) {

               futures.push_back(std::async([]() {

       

                   for (auto i = 0; i != 100000 / 40; i++) {

       

                       const int size = 10;

       

                       for (auto k = 0; k != size * size; k++) {

                           double* matrix1 = (double*)malloc(100 * sizeof(double));

                           double* matrix2 = (double*)malloc(100 * sizeof(double));

                           double* matrix3 = (double*)malloc(100 * sizeof(double));

       

                           for (auto i = 0; i != size; i++) {

                               for (auto j = 0; j != size; j++) {

                                   matrix1[i * size + j] = std::rand() / RAND_MAX;

                                   matrix2[i * size + j] = std::rand() / RAND_MAX;

                               }

                           }

       

                           double sum = 0;

                           for (auto i = 0; i != size; i++) {

                               for (auto j = 0; j != size; j++) {

                                   for (auto k = 0; k != size; k++) {

                                       sum += matrix1[i * size + k] * matrix2[k * size + j];

                                   }

                                   matrix3[i * size + j] = sum;

                                   sum = 0;

                               }

                           }

       

                           free(matrix1);

                           free(matrix2);

                           free(matrix3);

                       }

                   }

       

               }));

           }

           for (auto& entry : futures)

             entry.wait();