 	m_print(state);
 #endif
 
-	CUDA_SAFE_CALL(cudaMalloc((void**) &dMatrixAp.elements, m_size(MatrixAp)));
-	CUDA_SAFE_CALL(cudaMemcpy(dMatrixAp.elements,MatrixAp.elements, m_size(MatrixAp), cudaMemcpyHostToDevice));
-
-	CUDA_SAFE_CALL(cudaMalloc((void**) &dblock_CA.elements, m_size(block_CA)));
-	CUDA_SAFE_CALL(cudaMemcpy(dblock_CA.elements,block_CA.elements, m_size(block_CA), cudaMemcpyHostToDevice));
-
-	CUDA_SAFE_CALL(cudaMalloc((void**) &dblock_samples.elements, m_size(block_samples)));
-	CUDA_SAFE_CALL(cudaMemcpy(dblock_samples.elements,block_samples.elements, m_size(block_samples), cudaMemcpyHostToDevice));
-
-	CUDA_SAFE_CALL(cudaMalloc((void**) &dstate1.elements, m_size(state)));
-	CUDA_SAFE_CALL(cudaMemcpy(dstate1.elements,state.elements, m_size(state), cudaMemcpyHostToDevice));
-
-	CUDA_SAFE_CALL(cudaMalloc((void**) &dstate2.elements, m_size(state)));
-	CUDA_SAFE_CALL(cudaMemcpy(dstate2.elements,state.elements, m_size(state), cudaMemcpyHostToDevice));
+	CUDA_SAFE_CALL(cudaMalloc((void**) &device_MatrixAp.elements, m_size(MatrixAp)));
+	CUDA_SAFE_CALL(cudaMemcpy(device_MatrixAp.elements,MatrixAp.elements, m_size(MatrixAp), cudaMemcpyHostToDevice));
+
+	CUDA_SAFE_CALL(cudaMalloc((void**) &device_block_CA.elements, m_size(block_CA)));
+	CUDA_SAFE_CALL(cudaMemcpy(device_block_CA.elements,block_CA.elements, m_size(block_CA), cudaMemcpyHostToDevice));
+
+	CUDA_SAFE_CALL(cudaMalloc((void**) &device_block_samples.elements, m_size(block_samples)));
+	CUDA_SAFE_CALL(cudaMemcpy(device_block_samples.elements,block_samples.elements, m_size(block_samples), cudaMemcpyHostToDevice));
+
+	CUDA_SAFE_CALL(cudaMalloc((void**) &device_state1.elements, m_size(state)));
+	CUDA_SAFE_CALL(cudaMemcpy(device_state1.elements,state.elements, m_size(state), cudaMemcpyHostToDevice));
+
+	CUDA_SAFE_CALL(cudaMalloc((void**) &device_state2.elements, m_size(state)));
+	CUDA_SAFE_CALL(cudaMemcpy(device_state2.elements,state.elements, m_size(state), cudaMemcpyHostToDevice));
 
 	dim3 dimBlockCA(1, 1);
 	dim3 dimGridCA(state.cols / dimBlockCA.x, block_CA.rows / dimBlockCA.y);

#endif
		}
	//	tmp_state = m_multiplyblockdiag(MatrixAp,state,2);
		MatrixMultiplyKernel<<<dimGridA, dimBlockA>>>(dMatrixAp, dstate1, dstate2);
		dtmp_state = dstate1;
		dstate1 = dstate2;
		dstate2 = dtmp_state;
	//	state = tmp_state;
		i = i + blocksize;
	}

#endif
	
		cudaDeviceSynchronize();	
		cudaMemcpy(block_samples.elements, device_block_samples.elements, m_size(block_samples), cudaMemcpyDeviceToHost);

		//printf("%d\n", i);

