Quantcast
Viewing all articles
Browse latest Browse all 77

A strange behavior in array operations

Hello,

When I played with array operations in Cilk Plus, I found the same assignment might return different results with gcc and g++.  For example, in array[0:5] = array[10:5], we expect that five elements 10 to 14 are copied to elements 0 to 4 in order.  There is no overlap in the example.  It works when it is compiled with g++.  However, it goes awry when it is compiled with gcc.  Actually, another five elements 10 to 6 are copied.

Is it an error or a bug?  Thanks.

Configuration:

         gcc (Ubuntu 5.3.0-3ubuntu1~14.04) / g++ (Ubuntu 5.3.0-3ubuntu1~14.04)

Code:  arr.c

#include <stdio.h>
#include <cilk/cilk.h>

int main()
{
	int a[99];
	int n = 20;
	for(int i=0;i<n;i++)
		a[i] = i + 1;
	a[0:5] = a[10:5]; //<--------
	for(int i=0;i<n;i++)
		printf("a[%d] = %d\n",i,a[i]);
	return 0;
}

Compile with gcc:

         gcc arr.c -fcilkplus -lcilkrts​

./a.out
a[0] = 11
a[1] = 10
a[2] = 9
a[3] = 8
a[4] = 7
a[5] = 6
a[6] = 7
a[7] = 8
a[8] = 9
a[9] = 10
a[10] = 11
a[11] = 12
a[12] = 13
a[13] = 14
a[14] = 15
a[15] = 16
a[16] = 17
a[17] = 18
a[18] = 19
a[19] = 20

Compile with g++:

         g++ arr.c -fcilkplus -lcilkrts​

./a.out
a[0] = 11
a[1] = 12
a[2] = 13
a[3] = 14
a[4] = 15
a[5] = 6
a[6] = 7
a[7] = 8
a[8] = 9
a[9] = 10
a[10] = 11
a[11] = 12
a[12] = 13
a[13] = 14
a[14] = 15
a[15] = 16
a[16] = 17
a[17] = 18
a[18] = 19
a[19] = 20

 


Viewing all articles
Browse latest Browse all 77

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>