(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.oacc-c-c++-common/
mdc-refcount-3.c
       1  /* { dg-skip-if "" { *-*-* } { "-DACC_MEM_SHARED=1" } } */
       2  
       3  /* Variant of 'deep-copy-7.c'.  */
       4  
       5  #include <stdlib.h>
       6  #include <assert.h>
       7  #include <openacc.h>
       8  
       9  struct dc
      10  {
      11    int a;
      12    int *b;
      13  };
      14  
      15  int
      16  main ()
      17  {
      18    int n = 100, i, j, k;
      19    struct dc v = { .a = 3 };
      20  
      21    v.b = (int *) malloc (sizeof (int) * n);
      22  
      23    for (k = 0; k < 16; k++)
      24      {
      25        /* Here, we do not explicitly copy the enclosing structure, but work
      26  	 with fields directly.  Make sure attachment counters and reference
      27  	 counters work properly in that case.  */
      28  #pragma acc enter data copyin(v.a, v.b[0:n]) // 1
      29        assert (acc_is_present (&v.b, sizeof v.b));
      30        assert (acc_is_present (v.b, sizeof (int) * n));
      31  #pragma acc enter data pcopyin(v.b[0:n]) // 2
      32  #pragma acc enter data pcopyin(v.b[0:n]) // 3
      33  
      34  #pragma acc parallel loop present(v.a, v.b)
      35        for (i = 0; i < n; i++)
      36  	v.b[i] = k + v.a + i;
      37  
      38        switch (k % 5)
      39  	{ // All optional.
      40  	case 0:
      41  	  break;
      42  	case 1:
      43  	  ; //TODO PR95901
      44  #pragma acc exit data detach(v.b) finalize
      45  	  break;
      46  	case 2:
      47  	  ; //TODO PR95901
      48  #pragma acc exit data detach(v.b)
      49  	  break;
      50  	case 3:
      51  	  acc_detach_finalize ((void **) &v.b);
      52  	  break;
      53  	case 4:
      54  	  acc_detach ((void **) &v.b);
      55  	  break;
      56  	}
      57        assert (acc_is_present (&v.b, sizeof v.b));
      58        assert (acc_is_present (v.b, sizeof (int) * n));
      59        { // 3
      60  	acc_delete (&v.b, sizeof v.b);
      61  	assert (acc_is_present (&v.b, sizeof v.b));
      62  	acc_copyout (v.b, sizeof (int) * n);
      63  	assert (acc_is_present (v.b, sizeof (int) * n));
      64        }
      65        { // 2
      66  	acc_delete (&v.b, sizeof v.b);
      67  	assert (acc_is_present (&v.b, sizeof v.b));
      68  	acc_copyout (v.b, sizeof (int) * n);
      69  	assert (acc_is_present (v.b, sizeof (int) * n));
      70        }
      71        { // 1
      72  	acc_delete (&v.b, sizeof v.b);
      73  	assert (!acc_is_present (&v.b, sizeof v.b));
      74  	acc_copyout (v.b, sizeof (int) * n);
      75  	assert (!acc_is_present (v.b, sizeof (int) * n));
      76        }
      77  #pragma acc exit data delete(v.a)
      78  
      79        for (i = 0; i < n; i++)
      80  	assert (v.b[i] == k + v.a + i);
      81  
      82        assert (!acc_is_present (&v, sizeof (v)));
      83      }
      84  
      85    return 0;
      86  }