             cudaErrorCheck( cudaPeekAtLastError() );
             cudaErrorCheck( cudaDeviceSynchronize() );
     #endif
+            // copy the result flag back
+            cudaErrorCheck( cudaMemcpy(result_flag, host_solver->result, num_cond * sizeof(int), cudaMemcpyDeviceToHost) );
+            for(int i = 0; i < num_cond; ++i)
+                if (result_flag[i] != 0)
+                {
+                    printf("Thread %d returned error code %d\n", i, result_flag[i]);
+                    exit(result_flag[i]);
+                }
             // transfer memory back to CPU
             cudaErrorCheck( cudaMemcpy2D (y_temp, padded * sizeof(double),
                                             host_mech->y, padded * sizeof(double),

    free(y_temp);
    free(host_mech);
    free(host_solver);
    cudaErrorCheck( cudaDeviceReset() );

    return 0;


    dim3 dimGrid (padded / TARGET_BLOCK_SIZE, 1 );
    dim3 dimBlock(TARGET_BLOCK_SIZE, 1);
    int* result_flag = (int*)malloc(padded * sizeof(int));

// flag for ignition
#ifdef IGN
