1
votes

I have this code and I'm trying to figure out what's wrong with it? It gives me errors although I tried fixing them. I tried adding libraries and fixing the vector part but I can't get what exactly the error is.

Severity    Code    Description Project File    Line    Suppression State
Error   C3034   OpenMP 'master' directive cannot be directly nested within 'for' directive  ConsoleApplication8


#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <chrono>
#include <algorithm>
#include <omp.h>
#define NUM_THREADS 2
#define  DIM 10
#define COUNT 0
using namespace std;

int main(int VECTOR_SIZE, char** argv) {
    int result;
    int tid;
    int* local_count = (int*)malloc(sizeof(int) * NUM_THREADS * DIM);
    int* vector = (int*)malloc(sizeof(int) * VECTOR_SIZE);
    for (int j = 0; j < COUNT; j++) {
#pragma omp parallel
        tid = omp_get_num_threads() * DIM;
        if (tid < 0) tid = 0;
#pragma omp for
        for (int i = 0; i < DIM; i++) {
            local_count[tid] += vector[i] * 2;
#pragma omp master
            for (int k = 0; k < NUM_THREADS; k++)
                result += local_count[k];
        }

        cout << "Execution Time: " << result;
        return 0;
    }
}
"It gives me errors " what exactly does that mean?463035818_is_not_a_number
What are the exact errors?takendarkk
If you want help with errors it's a good idea to include the error messages in the question. Helps a lot.john
COUNT is 0, so your for loop never executesyano
Severity Code Description Project File Line Suppression State Error C3034 OpenMP 'master' directive cannot be directly nested within 'for' directiveAnon