OpenMP - array-initialisation problem

I am dabbling in OpenMP, and now I am trying to create a league of teams with the OpenMP num_teams construct.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #include <omp.h>
  #include <stdio.h>

  using namespace std;

  int main(void)
  {

    #pragma omp parallel target num_teams(3)

    #pragma omp parallel num_threads(3)
   
       int files = {};
   
      #pragma omp for ordered
      for(int n=0; n<20; ++n) {
		  
		  files[n] = n; 
		  
		  #pragma omp ordered
		  cout << files[0] << endl;
	  } 
   
   
    return 0;
  }
 


Nevertheless, there seem to be some problems with the array:


test.cpp:18:5: error: use of undeclared identifier 'files'
files[n] = n;
^
test.cpp:21:5: error: use of undeclared identifier 'cout'
cout << files[0] << endl;
^
test.cpp:21:13: error: use of undeclared identifier 'files'; did you mean 'fileno'?
cout << files[0] << endl;
cout << files[0] << endl;


Where / how do I have to declare the array so that the erros disappear?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <omp.h>
#include <iostream>   // Used for C++ console i/o

using namespace std;

constexpr int ARRSZ = 20;   // Specifies size of array as compile time costant

int main(void)
{
    #pragma omp parallel target num_teams(3)

    #pragma omp parallel num_threads(3)
   
    int files[ARRSZ];   // Define files as an array of ARRSZ elements
   
    #pragma omp for ordered

    for (int n = 0; n < ARRSZ; ++n) {
        files[n] = n; 
  
        #pragma omp ordered
        cout << files[0] << endl;
    }
     
    return 0;
}

Last edited on
Thanks :)
Topic archived. No new replies allowed.