Private clause can be used to make thread- private versions of such variables:
#pragma omp parallel private(id) { int id = omp_get_thread_num(); cout << "My thread num" << id << endl; }