 {
     const int ThreadsInBlock = 512;
     int iterations;
-    double *A, *B, *C;
-    double ref_value;
-    float gputime_ref, gputimes[N_TESTS];
     stream *s;
 
     cudaDeviceProp prop;

    cudaGetDeviceProperties(&prop, 0);
    iterations = (prop.multiProcessorCount + 1) / 2;

    // Add here allocations for managed memory
    CUDA_CHECK( cudaMallocManaged((void**)&A, sizeof(double) * N) );
    CUDA_CHECK( cudaMallocManaged((void**)&B, sizeof(double) * N) );
    CUDA_CHECK( cudaMallocManaged((void**)&C, sizeof(double) * N) );
    
    for(int i = 0; i < N; ++i) {
        A[i] = 1.0;
        B[i] = 2.0;
    }


    
    // Check the timings of default stream first
    default_stream(C, A, B, N, &gputime_ref, ThreadsInBlock,
                   iterations);
    //free memory allocations
    CUDA_CHECK( cudaFree((void*)A) );
    CUDA_CHECK( cudaFree((void*)B) );
    CUDA_CHECK( cudaFree((void*)C) );


    int errorsum = 0;

    // Now do it with streams, note that each stream will need to allocate its
    // own memory area 
    // Here we loop over the test. On each iteration, we double the number
    // of streams
    for(int strm = 0; strm < N_TESTS; strm++) {
        int stream_count = 1<<strm;
        create_streams(stream_count, N, &s);

        //set value
        for(int i = 0; i < stream_count; ++i) {
           for(int j = 0; j < s[i].len; ++j) {
              s[i].A[j] = 1.0;
              s[i].B[j] = 2.0;
           }
        }
        

        streamtest(s, stream_count, &gputimes[strm], ThreadsInBlock, iterations);

        ref_value = 3.0 * ITER_MULTIPLIER * iterations;
        //check value
        for(int i = 0; i < stream_count; ++i) {
           for(int j = 0; j < s[i].len; ++j) {
              errorsum += s[i].C[j] - ref_value;              
           }
        }
        
        destroy_streams(stream_count, s);
    }


    printf("Error sum = %i\n", errorsum);
    printf("Time elapsed for reference run: %f\n", gputime_ref / 1000.);
    for(int i = 0; i < N_TESTS; i++) {
        printf("Time elapsed for test %2i:       %f\n", 1<<i,
               gputimes[i] / 1000.);
    }


    return 0;

{
    for(int i = 0; i < nstreams; i++) {
        CUDA_CHECK( cudaStreamDestroy(s[i].strm) );
        //TODO: Free memory allocations
        CUDA_CHECK( cudaFree((void*)s[i].A) );
        CUDA_CHECK( cudaFree((void*)s[i].B) );
        CUDA_CHECK( cudaFree((void*)s[i].C) );
