# CLBufferWrite Writes into the OpenCL buffer and returns the number of written elements. ``` uint  CLBufferWrite(    int          buffer,                    // A handle to the OpenCL buffer    const void&  data[],                    // An array of values    uint         buffer_offset=0,           // An offset in the OpenCL buffer in bytes, 0 by default    uint         data_offset=0,             // An offset in the array in elements, 0 by default    uint         data_count=WHOLE_ARRAY     // The number of values from the array for writing, the whole array by default    ); ``` There are also versions for handling [matrices and vectors](/en/docs/matrix). Writes the values from the matrix to the buffer and returns true if successful. ``` uint  CLBufferWrite(    int           buffer,                    // a handle to the OpenCL buffer    uint          buffer_offset,             // an offset in the OpenCL buffer in bytes    matrix     &mat                       // the values matrix for writing to the buffer    ); ``` Writes the values from the vector to the buffer and returns true if successful. ``` uint  CLBufferWrite(    int           buffer,                    // a handle to the OpenCL buffer    uint          buffer_offset,             // an offset in the OpenCL buffer in bytes    vector     &vec                       // the values vector for writing to the buffer    ); ``` Parameters buffer [in]  A handle of the OpenCL buffer. data[] [in]  An array of values that should be written in the OpenCL buffer. Passed by reference. buffer_offset [in]  An offset in the OpenCL buffer in bytes, from which writing begins. By default, writing start with the very beginning of the buffer. data_offset [in]  The index of the first array element, starting from which values from the array are written in the OpenCL buffer. By default, values from the very beginning of the array are taken. data_count [in]  The number of values that should be written. All the values of the array, by default. mat [out]  The matrix for reading data from the buffer can be any of the three types — matrix, matrixf or matrixc. vec [out]  The vector for reading data from the buffer can be of any of the three types — vector, vectorf or vectorc. Return Value The number of written elements. 0 is returned in case of an error. For information about the error, use the [GetLastError()](/en/docs/check/getlasterror) function. true if a matrix or a vector is handled successfully, otherwise false. Note For one-dimensional arrays, the number of the element, with which reading of data for writing into an OpenCL buffer begins, is calculated taking into account the [AS_SERIES](/en/docs/array/arraygetasseries) flags. An array of two or more dimensions is presented as one-dimensional. In this case, data_offset is the number of elements that should be skipped in the presentation, not the number of elements in the first dimension. Example of matrix multiplication using the [MatMul](/en/docs/matrix/matrix_products/matrix_matmul) method and parallel computing in OpenCL ``` #define M       3000      // the number of rows in the first matrix #define K       2000      // the number of columns in the first matrix is equal to the number of rows in the second one  #define N       3000      // the number of columns in the second matrix   //+------------------------------------------------------------------+ const string clSrc=   "#define N     "+IntegerToString(N)+"                              \r\n"   "#define K     "+IntegerToString(K)+"                              \r\n"   "                                                                  \r\n"   "__kernel void matricesMul( __global float *in1,                   \r\n"   "                           __global float *in2,                   \r\n"   "                           __global float *out  )                 \r\n"   "{                                                                 \r\n"   "  int m = get_global_id( 0 );                                     \r\n"   "  int n = get_global_id( 1 );                                     \r\n"   "  float sum = 0.0;                                                \r\n"   "  for( int k = 0; k < K; k ++ )                                   \r\n"   "     sum += in1[ m * K + k ] * in2[ k * N + n ];                  \r\n"   "  out[ m * N + n ] = sum;                                         \r\n"   "}                                                                 \r\n"; //+------------------------------------------------------------------+ //| Script program start function                                    | //+------------------------------------------------------------------+ void OnStart()  { //--- initialize the random number generator   MathSrand((int)TimeCurrent()); //--- fill in the matrices of a given size with random values   matrixf mat1(M, K, MatrixRandom) ;    // first matrix   matrixf mat2(K, N, MatrixRandom);     // second matrix   //--- calculate the product of matrices using naive method   uint start=GetTickCount();   matrixf matrix_naive=matrixf::Zeros(M, N);// the result of multiplying two matrices is set here   for(int m=0; m