0

I am new to OpenMP... Please help me with this dumb question. Thank you :)

Basically, I want to use OpenMP to speed up two for loops. But I do not know why it keeps saying: invalid controlling predicate for the for loop.

By the way, my GCC version is gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005, and OS I am using is Ubuntu 16.10.

Basically, I generate a toy data that has a typical Key-Value style, like this:

Data = {
    "0": ["100","99","98","97",..."1"];
    "1": ["100","99","98","97",..."1"];
    ...
    "999":["100","99","98","97",..."1"];
}

Then, for each key, I want to compare its value with the rest of the keys. Here, I sum them up through "user1_list.size()+user2_list.size();". As for each key, the sum-up process is totally independent of other keys, which means this works for parallelism.

Here is my toy example code.

#include <map>
#include <vector>
#include <string>
#include <iostream>

#include "omp.h"

using namespace std;

int main(){
    // Create Data
    map<string, vector<string>> data;
    for(int i=0; i != 1000; i++){
        vector<string> list;
        for (int j=100; j!=0; j--){
            list.push_back(to_string(j));
        }
        data[to_string(i)]=list;
    }
    cout << "Data Total size: " << data.size() << endl; 

    int count = 1;
    #pragma omp parallel for private(count)
    for (auto it=data.begin(); it!=data.end(); it++){
        //cout << "Evoke Thread: " << omp_get_thread_num();
        cout << " count: " << count << " / " << data.size() << endl;
        count ++;
        string user1 = it->first;
        vector<string> user1_list = it->second;

        for (auto it2=data.begin(); it2!=data.end(); it2++){
            string user2 = it2->first;
            vector<string> user2_list = it2->second;

            cout << "u1:" << user1 << " u2:" << user2;
            int total_size = user1_list.size()+user2_list.size();
            cout << " total size: " << total_size << endl;
        }
    }
    return 0;
}
uniqueliu
  • 79
  • 2
  • 9
  • It looks like this question suggests you should be using an `int` for your loop variable, rather than what looks like a pointer to a list from an enumerator https://stackoverflow.com/questions/17575329/invalid-controlling-predicate-compiler-error-using-openmp – GregHNZ Nov 12 '17 at 01:25
  • Yes. But here I need to iteratively extract values from the vector. – uniqueliu Nov 12 '17 at 01:40
  • You cannot just `omp for` a loop over a non-random-access-iterator. There are many possible ways to work around that, but the highly synthetic nature of your example makes it hard to tell which one is suitable for you. Could you elaborate the nature of your practical data structure and computational tasks? – Zulan Nov 12 '17 at 08:40
  • I want to create a graph among a set of people, where each person has a set of features such as "Male," "Height,: etc. The nodes in the graph are peoples, and edges should be the similarity among people. So, if I want to create edges among people, I need to calculate the similarity between every two people. That is an O(N^2) problem, but due to that each computation is highly independent of others, so I think it is possible to parallelism. – uniqueliu Nov 12 '17 at 15:28

0 Answers0