(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.oacc-c-c++-common/
lib-88.c
       1  /* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */
       2  
       3  #include <stdio.h>
       4  #include <pthread.h>
       5  #include <string.h>
       6  #include <stdlib.h>
       7  #include <ctype.h>
       8  #include <openacc.h>
       9  
      10  unsigned char *x;
      11  void *d_x;
      12  const int N = 256;
      13  
      14  static void *
      15  test (void *arg)
      16  {
      17    int i;
      18  
      19    if (acc_get_current_cuda_context () != NULL)
      20      abort ();
      21  
      22    if (acc_is_present (x, N) != 1)
      23      abort ();
      24  
      25    memset (x, 0, N);
      26  
      27    acc_copyout (x, N);
      28  
      29    for (i = 0; i < N; i++)
      30      {
      31        if (x[i] != i)
      32  	abort ();
      33  
      34        x[i] = N - i - 1;
      35      }
      36  
      37    d_x = acc_copyin (x, N);
      38  
      39    return 0;
      40  }
      41  
      42  int
      43  main (int argc, char **argv)
      44  {
      45    const int nthreads = 1;
      46    int i;
      47    pthread_attr_t attr;
      48    pthread_t *tid;
      49  
      50    acc_init (acc_device_default);
      51  
      52    x = (unsigned char *) malloc (N);
      53  
      54    for (i = 0; i < N; i++)
      55      {
      56        x[i] = i;
      57      }
      58  
      59    d_x = acc_copyin (x, N);
      60  
      61    if (acc_is_present (x, N) != 1)
      62      abort ();
      63  
      64    if (pthread_attr_init (&attr) != 0)
      65      perror ("pthread_attr_init failed");
      66  
      67    tid = (pthread_t *) malloc (nthreads * sizeof (pthread_t));
      68  
      69    for (i = 0; i < nthreads; i++)
      70      {
      71        if (pthread_create (&tid[i], &attr, &test, (void *) (unsigned long) (i))
      72  	  != 0)
      73  	perror ("pthread_create failed");
      74      }
      75  
      76    if (pthread_attr_destroy (&attr) != 0)
      77      perror ("pthread_attr_destroy failed");
      78  
      79    for (i = 0; i < nthreads; i++)
      80      {
      81        void *res;
      82  
      83        if (pthread_join (tid[i], &res) != 0)
      84  	perror ("pthread join failed");
      85      }
      86  
      87    if (acc_is_present (x, N) != 1)
      88      abort ();
      89  
      90    memset (x, 0, N);
      91  
      92    acc_copyout (x, N);
      93  
      94    for (i = 0; i < N; i++)
      95      {
      96        if (x[i] != N - i - 1)
      97  	abort ();
      98      }
      99  
     100    if (acc_is_present (x, N) != 0)
     101      abort ();
     102  
     103    return 0;
     104  }
     105  
     106  /* { dg-output "" } */