[Rd] OpenMP problem with 64-bit Rtools

Radford Neal radford at cs.toronto.edu
Fri Aug 21 20:38:26 CEST 2015


I've been getting pqR to work on windows systems, and in the process
have discovered various problems with R core versions of R and with
Rtools.

One is with the implementation of OpenMP in 64-bit Rtools.  This
problem is in Rtools215 and Rtools33, and presumably all the ones in
between.  You can see the problem with the following test program:

#include <stdio.h>
#include <omp.h>
static struct { omp_lock_t lock; char pad[20]; } s;

void show_pad(void)
{ int i;
  for (i = 0; i<20; i++) printf(" %02x",s.pad[i]);
  printf("\n");
}

int main(void)
{ int i;
  printf("size: %d\n",(int)sizeof s);
  for (i = 0; i<20; i++) s.pad[i] = 7;
  show_pad();
  omp_init_lock (&s.lock);
  show_pad();
  omp_set_lock (&s.lock);
  show_pad();
  return 0;
}

When compiled using the Rtools compiler with "gcc -m32 -fopenmp", it
works fine, printing three lines of output with all numbers being 7.
But when compiled with "gcc -m64 -fopenmp", the last two lines have
four zeros at the beginning.

What's happended is that omp_init_lock has written zeros to four bytes
after the end of the omp_lock_t structure.

The reason for this appears to be that the omp.h file included is
appropriate only for the 32-bit version of the openMP library.  As
far as I can see, there is no 64-bit version of this include file
in the stuff installed with Rtools.

This problem obviously has the potential to affect many packages that
use OpenMP, though simple OpenMP applications may not do anything for
which the incorrect omp.h include file makes a difference.

   Radford Neal



More information about the R-devel mailing list