OpenMp 3.0 and iterators


the OpenMp 3.0 specification support loop parallelization for random_access_iterators. This works fine for pgCC 9.03 and a iterator over a std::vector.

Now i wrote my own iterator class for my own container (example code below). I inheritated this iterator class from the std::iterator<Category, T, Distance, Pointer, Reference> class to get a STL conform iterator. This works fine with GNU g++ 4.4.1, but for pgCC I get an error:

$ pgCC -o test -mp
PGCC-S-0094-Illegal type conversion required ( 87)
PGCC-S-0094-Illegal type conversion required ( 87)
PGCC/x86 Linux 9.0-3: compilation completed with severe errors


#include <stdlib.h>
#include <omp.h>

#define SIZE 26

class SpecialMap;

class SpecialMapIterator: public std::iterator<std::random_access_iterator_tag , SpecialMap>{

SpecialMapIterator() : it_(0){}
SpecialMapIterator& operator++(){++it_; return *this;}
SpecialMapIterator& operator++(int){it_++; return *this;}
SpecialMapIterator& operator–(){–it_; return *this;}
SpecialMapIterator& operator–(int){it_–; return *this;}

typedef ptrdiff_t difference_type;

SpecialMapIterator& operator+=(difference_type rhs){
return *this;

char& operator*() {return it_->second;}
const char& operator*() const{return it_->second;}

bool operator<=(const SpecialMapIterator& rhs){return it_!=rhs.it_; }
bool operator<(const SpecialMapIterator& rhs){return it_!=rhs.it_;}
bool operator!=(const SpecialMapIterator& rhs){return it_!=rhs.it_;}
bool operator==(const SpecialMapIterator& rhs){return (it_==rhs.it_);}

friend class SpecialMap;
friend difference_type operator-(SpecialMapIterator it1, SpecialMapIterator it2);

SpecialMapIterator(std::map<int, char>::iterator it) : it_(it){}
std::map<int, char>::iterator it_;

class SpecialMap{
typedef SpecialMapIterator iterator;
typedef SpecialMapIterator const_iterator;

iterator begin(){return SpecialMapIterator(map_.begin());}
iterator end(){return SpecialMapIterator(map_.end());}

char& operator(const int i){ return map_> ;}

std::map<int, char> map

SpecialMapIterator::difference_type operator-(SpecialMapIterator it1, SpecialMapIterator it2){
SpecialMapIterator::difference_type count = 0;
while(it2 != it1){
return count;

int main (int argc, char** argv){
typedef SpecialMap maptype;
maptype myMap;

char c=‘a’;
for(int i=0; i<SIZE; i++){
myMap> =c;

maptype::iterator itM;
int i = 0;

#pragma omp parallel for
for(itM=myMap.begin(); itM < myMap.end(); itM++){

#pragma omp critical
std::cout << *itM << ": " <<omp_get_thread_num()<< ": " <<++i <<std::endl;
return 0;

The openMP specification does not really say, in which case a iterator is a “RandomAccessIterator”. So is this a feature in gcc or a bug in pgCC? Or is there another possibility to write my own RandomAccessIterator or wrap it somehow?

This is a bug in the compiler - we’re not accounting for calls to class operators
as a valid test in the omp “for” loop. We’ve filed the bug :160063 , and we
expect to fix it soon.

Thank you for the test case.

Thanks for your quick response. Im looking forward for the fix to continue evaluating the compiler. :-)


I saw that there was a new release last week. Does it contain a fix for this problem?

Hi timiem,

I checked with Deb on the status of this problem. She has worked on it but has not checked a fix into a release compiler. It should be ready for the next major release due later this year.

Thanks for checking,