Exemple #1
0
int main(int argc, char *argv[])
{

    int num_nodes = 1024;
    size_t buf_size = num_nodes * num_nodes * sizeof(uint);

    uint *path_dist_mtx = (uint *) malloc(buf_size);
    uint *path_mtx = (uint *) malloc(buf_size);

    fill_rand(path_dist_mtx, num_nodes * num_nodes, 0, 200);

    int i, j;
    for (i = 0; i < num_nodes; i++) {
        path_dist_mtx[i * num_nodes + i] = 0;
    }

    for (i = 0; i < num_nodes; i++) {
        for (j = 0; j < i; ++j) {
            path_mtx[i * num_nodes + j] = i;
            path_mtx[j * num_nodes + i] = j;
        }
        path_mtx[i * num_nodes + i] = i;
    }

    floydWarshallCPU(path_dist_mtx, path_mtx, num_nodes); 

    for (i = 0; i < num_nodes ; i++) {
        printf("%i %d\n", i, path_mtx[i]);
    }
}
int main()
{
  double *A, suma, tiempo;
  

  A = (double *)malloc(N*sizeof(double));

  tiempo = omp_get_wtime();

#pragma parallel
  {
    #pragma omp sections
    {
      #pragma section
      {
	fill_rand(N, A);        // Productor
	flag=1;
        #pragma omp flush
      }
      #pragma section
      {
	suma = Sum_array(N, A);  // Consumidor
      }
    }
  }
  tiempo = omp_get_wtime() - tiempo;

  printf(" La suma es %f en %f segundos\n",suma, tiempo);
}
Exemple #3
0
void cleanup_rand(void *obj, int iter) {
    srand(RANDOM_SEED);
    int i;
    char buf[20];
    for(i = 1; i < iter; ++i) {
        fill_rand(buf, 10);
        if(del(obj, buf)) {
            printf("Failed to delete: %s\n", buf);
        }
    }
}
int main()
{
  double *A, sum, runtime;
  int numthreads, flag = 0;

  omp_set_num_threads(Nthreads);

  A = (double *)malloc(N*sizeof(double));

  #pragma omp parallel
  {
     #pragma omp master
     {
        numthreads = omp_get_num_threads();
        if(numthreads != 2)
        {
           printf("error: incorect number of threads, %d \n",numthreads);
           exit(-1);
        }
        runtime = omp_get_wtime();
     }
     #pragma omp barrier

     #pragma omp sections
     {
        #pragma omp section
        {
           fill_rand(N, A);
           #pragma omp flush
           flag = 1;
           #pragma omp flush (flag)
        }
        #pragma omp section
        {
           #pragma omp flush (flag)
           while (flag != 1){
              #pragma omp flush (flag)
           }

           #pragma omp flush 
           sum = Sum_array(N, A);
        }
      }
      #pragma omp master
         runtime = omp_get_wtime() - runtime;
   }  

   printf(" with %d threads and %lf seconds, The sum is %lf \n",numthreads,runtime,sum);
}
Exemple #5
0
void set_rand(void *obj, int iter) {
    srand(RANDOM_SEED);
    int i;

    char buf[20];
    for(i = 1; i < iter; ++i) {
        fill_rand(buf, 10);
        void* val = (void *)(size_t)i;

        if(add(obj, (void *)&buf, val)) {
            printf("Failed to insert `%s`\n", buf);
            exit(-1);
        }
    }
}
Exemple #6
0
int main()
{
  double *A, sum, runtime;
  int flag = 0;

  A = (double *)malloc(N*sizeof(double));

  runtime = omp_get_wtime();

  fill_rand(N, A);        // Producer: fill an array of data

  sum = Sum_array(N, A);  // Consumer: sum the array
   
  runtime = omp_get_wtime() - runtime;

  printf(" In %f seconds, The sum is %f \n",runtime,sum);
}
Exemple #7
0
/*
 * Hog numbytes of memory. It is initialized and locked in.
 */
void hog_memory(u64 numbytes)
{
	int rc;

	Hog = malloc(numbytes);
	if (!Hog)
		fatal("Couldn't hog %llu bytes of memory", numbytes);
	Numbytes = numbytes;
	if (!Init_rand) {
		twister_random_seed();
		Init_rand = TRUE;
	}
	fill_rand(Hog, numbytes);
	rc = mlock(Hog, numbytes);
	if (rc)
		fatal("Couldn't lock memory:");
}
Exemple #8
0
int
main( void )
{
    struct reader *pp_readers[3];

    test_init();

#ifndef TEST_NET
    char psz_tmp_path[] = "/tmp/libvlc_XXXXXX";
    char *psz_url;
    int i_tmp_fd;

    log( "Test random file with libc, and stream\n" );
    i_tmp_fd = vlc_mkstemp( psz_tmp_path );
    fill_rand( i_tmp_fd, RAND_FILE_SIZE );
    assert( i_tmp_fd != -1 );
    assert( asprintf( &psz_url, "file://%s", psz_tmp_path ) != -1 );

    assert( ( pp_readers[0] = libc_open( psz_tmp_path ) ) );
    assert( ( pp_readers[1] = stream_open( psz_url ) ) );

    test( pp_readers, 2, NULL );
    for( unsigned int i = 0; i < 2; ++i )
        pp_readers[i]->pf_close( pp_readers[i] );
    free( psz_url );

    close( i_tmp_fd );
#else

    log( "Test http url with stream\n" );
    alarm( 0 );
    if( !( pp_readers[0] = stream_open( HTTP_URL ) ) )
    {
        log( "WARNING: can't test http url" );
        return 0;
    }

    test( pp_readers, 1, HTTP_MD5 );
    for( unsigned int i = 0; i < 1; ++i )
        pp_readers[i]->pf_close( pp_readers[i] );

#endif

    return 0;
}
Exemple #9
0
void get_rand(void *obj, int iter) {
    srand(RANDOM_SEED);
    int i;

    char buf[20];
    for(i = 1; i < iter; ++i) {
        fill_rand(buf, 10);
        void *out = find(obj, buf);
        if(out) {
            int val = (size_t)out;
            if(val != i) {
                printf("invalid value: %d != %d\n", i, val);
                exit(-1);
            }
        } else {
            printf("Failed to get `%s`\n", buf);
            exit(-1);
        }
    }

}
Exemple #10
0
int main()
{
    std::vector<int> v(10);
    fill_rand(v);
    std::copy(v.begin(), v.end(), std::ostream_iterator<int>(std::cout, " "));
}
Exemple #11
0
int main()
{
 int k=0,n=1,*A,*B,*C,h,i,j,c,num,c_i,b_i,m,q,r,l,e;
 
 while (n%2==1) scanf("%d",&n);
 
 A=new int [n];
 B=new int [n/2];
 C=new int [n/2];
 
 fill_rand(n,A);
 print_mas(n,A);
 
                                           // B - odd , C - even
 num=1;
 c=num;
 m=n;
 i=0; j=0; k=0; c_i=0; b_i=0;
 e=1;
 q=e;
 r=e;
 
while(m != 1)
{ 
 while(k < m)
 {
  if(k%2 != 0)           // нечетные 
  {
   for(; i < c; i++)
   {
    C[c_i]=A[i];
    c_i++;
   }
  }
  
  else
  {
   for(; i < c; i++)   // четные
   {
    B[b_i]=A[i];
    b_i++;
   }      
  
  }
  c+=num;
  k++;
 }   
 
 br; 
 print_mas(n/2,B);
 br;
 print_mas(n/2,C);    
 
 br; br;
 
 m/=2;

 b_i=0;
 
                                           // merging
 k=0;
 i=0; 
 l=0;
 
 
 for(c_i=0; c_i < n; c_i++)
 {
  q=r=num;           
  while(q != 0 && r != 0) // распределение
 {     
  if(B[i] <= C[k])
  {
   A[l]=B[i];
   i++;
   q=q-1;
  }
  
  else
  {
   A[l]=C[k];
   k++;
   r=r-1;
  }
  
  l++;
 }    
 
 while(q > 0)              // дополнение
 {
  A[l]=B[i];
  l++;
  i++;
  q--;
 } 
 
 while(r > 0)              // дополнение
 {
  A[l]=C[k];
  l++;
  k++;
  r--;
 } 
 }
 
 k=0;
 i=0;
 num*=2;
 c=num; 
 q=num; r=num;
 c_i=0; 
 
 printf("("); print_mas(n,A); printf(")");
 
} 
    
 getch(); return 0;
}
Exemple #12
0
int main(int argc, char *argv[])
{
    init_rpc(argv[1]);

    cl_platform_id platform;
    cl_device_id device;
    cl_context context;
    cl_command_queue queue;
    cl_program program;
    cl_kernel kernel;
    cl_mem d_input_r;
    cl_mem d_input_i;

    int length = 1024;
    size_t buf_size = length * sizeof(float);
    float *input_r, *input_i, *output_r, *output_i;

    posix_memalign((void **)&input_r, 16, buf_size);
    posix_memalign((void **)&input_i, 16, buf_size);
    posix_memalign((void **)&output_r, 16, buf_size);
    posix_memalign((void **)&output_i, 16, buf_size);

    fill_rand(input_r, length, 0, 255);
    fill_rand(input_i, length, 0, 0);
    memcpy(output_r, input_r, buf_size);
    memcpy(output_i, input_i, buf_size);

    size_t local_work_size[1];
    size_t global_work_size[1];

    local_work_size[0] = 64;
    global_work_size[0] = 64;

    const char *source = load_program_source("FFT.cl");
    size_t source_len = strlen(source);;
    cl_uint err = 0;

    char *flags = "-x clc++";

    clGetPlatformIDs(1, &platform, NULL);
    printf("platform %p err %d\n", platform, err);

    clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 1, &device, &err);
    printf("device %p err %d\n", device, err);

    context = clCreateContext(0, 1, &device, NULL, NULL, &err);
    printf("context %p err %d\n", context, err);

    queue = clCreateCommandQueue(context, device, 0, &err);
    printf("queue %p err %d\n", queue, err);

    program = clCreateProgramWithSource(context, 1, &source, &source_len, &err);
    printf("program %p err %d\n", program, err);

    err = clBuildProgram(program, 0, NULL, flags, NULL, NULL);
    printf("err %d\n", err);

    kernel = clCreateKernel(program, "kfft", NULL);
    printf("kernel %p\n", kernel);

    d_input_r = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
        buf_size, input_r, &err);
    printf("d_input_r %p err %d\n", d_input_r, err);

    d_input_i = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
        buf_size, input_i, &err);
    printf("d_input_i %p err %d\n", d_input_i, err);

    err = clSetKernelArg(kernel, 0, sizeof(cl_mem), (void*)&d_input_r);
    printf("err %d\n", err);

    err = clSetKernelArg(kernel, 1, sizeof(cl_mem), (void*)&d_input_i);
    printf("err %d\n", err);

    err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, global_work_size,
        local_work_size, 0, NULL, NULL);
    printf("err %d\n", err);

    clFinish(queue);

    err = clEnqueueReadBuffer(queue, d_input_r, CL_TRUE, 0, buf_size, output_r,
        0, NULL, NULL);
    printf("err %d\n", err);

    err = clEnqueueReadBuffer(queue, d_input_i, CL_TRUE, 0, buf_size, output_i,
        0, NULL, NULL);
    printf("err %d\n", err);

    int i;
    for (i = 0; i < length; i++) {
        printf("%i %f %f\n", i, output_r[i], output_i[i]);
    }

    clReleaseMemObject(d_input_r);
    clReleaseMemObject(d_input_i);
    clReleaseProgram(program);
    clReleaseKernel(kernel);
    clReleaseCommandQueue(queue);

}