#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/timeb.h>
#include <omp.h>
#include <stdio.h>
#include <math.h>
#include <string.h>

/*double currentTime()
{
    return omp_get_wtime();
}*/

double currentTime() {
    struct timeb tm;
    ftime(&tm);
    return (double) tm.time + (double) tm.millitm / 1000.0;
}


int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        printf("Usage: %s \n", argv[0]);
        return 0;
    }

    int n = atoi(argv[1]);

    double* x = (double*)malloc(sizeof(double) * n);
 

    double idrandmax = 1.0 / RAND_MAX;
    double a = idrandmax * rand();
    int j;
    for (j = 0; j < n; j++)
    {
        x[j] = idrandmax * rand();
//        y[j] = idrandmax * rand();
    }


    double tick = currentTime();
    #pragma omp target data map( x[0:n])
     {
    double *p;
    p=&x[0];
    #pragma omp target map (p[3:7])
    x[2]=0;
    x[8]=0;
    x[8]=1;
     }
    double sec = currentTime()-tick;
    printf("time:\t\t%4f\n", sec * 1.0e3);
    
    free(x);
 
    return 0;
}
