Thread: Dot Product (includes attachment)

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    16

    Question Dot Product (includes attachment)

    Is anyone familiar with BLAS (Basic Linear Algebra Subprograms)?

    I am trying to use the dot product subtroutine (dot.c in a C program to multiply two arrays(matrix). The subroutine is already written, but I don't know how to call the subroutine is my program. I have attached the subroutine. PLEASE HELP!!!

  2. #2
    Registered User
    Join Date
    Nov 2003
    Posts
    16
    test

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well you'd better attach your program for calling it as well.
    It's all too easy to make something which is compatible with calling that function, but it could still leave you in the dark.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    16

    Dot product

    I don't understand what you are saying

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    51
    salem is saying post not just the function but the program that utilises the c_sdot function aswell.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Code:
    void c_sdot(enum blas_conjugate conj,
                int n, 
                float alpha, 
                const float* x, int incx, 
                float beta,
                const float* y, int incy, 
                float* r)
    Well you could call it
    Code:
    float a[10], b[10], c[10];
    c_sdot( ?, 0, 1.0, a, 2, 2.0, b, 2, c );
    or
    Code:
    float *a, *b, *c;
    c_sdot( ?, 0, 1.0, a, 2, 2.0, b, 2, c );
    Both are just as likely to make sense to the compiler (from a syntax point of view), but the 2nd one is much more likely to crash if you try and run it.

    I've no idea what enum blas_conjugate is, so you need to look that up and replace the ? parameter

    So the question remains, what do YOU have by way of existing variables to call this function with?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    16
    well that is the problem i dont know what code to write in order to call this subroutine

  8. #8
    Registered User
    Join Date
    Nov 2003
    Posts
    16

    Dot product

    i have attached a new document that might explain everything a little better

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Well I have looked at your code and all I can say is.....geez.

    There is an easier way to multiply matrices together as long as the matrices meet certain size requirements. Matrix math is simply row * column.

    For instance to multilpy 2 4x4 matrices together:

    Code:
    void MatrixMultiply44(double mat1[4][4],double mat2[4][4],double resultmatrix[4][4])
    {
      for (int i=0;i<4;i++)
      {
        for (int j=0;j<4;j++)
        {
          resultmatrix[i][j]=0.0;
          for (int k=0;k<4;k++)
          {
            resultmatrix[i][j]+=mat1[i][k]*mat2[k][j];
          }
        }
      }
    }

    Look up matrix multiplication on www.gamedev.net and it will show you how to multiply matrices of different row and column dimensions together - they must, however, meet certain criteria.

    It looks as though your code might be trying to find the determinant of the matrix, although there is an easier way to do that as well.

  10. #10
    Registered User
    Join Date
    Nov 2003
    Posts
    16
    i understand your method.............but i have to use the dot product(which is the function that is in the attachment)

  11. #11
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Then unless you explain what <cblas.h> is or what you are doing we can't help you.

    Seems like a contorted way to multiply 2 matrices together. OpenGL and DirectX both multiply matrices together at break neck speeds. Why the heck are you doing it this way.

    I see no benefit.

  12. #12
    Registered User
    Join Date
    Nov 2003
    Posts
    16
    blas (basic linear algebra subprograms) is one of many routines. The c_sdot routine is supposed to be used to calculate the dot product of two arrays that are float.

    I am doing it this way because the assignment is to:

    Declare two arrays and pass these arrays to the routine c_sdot so that it can compute the answer.

    I don't know why my professor wants us to do it this way...........i am confused also..............that is why i am asking for help

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > float array_a[3] = {1.0, 0.0, 1.0};
    > float array_b[3] = {3.0, 3.0, 3.0};
    > What is next?
    Well from what I posted last time, how about

    Code:
    float results[3];
    void c_sdot(conj,
                3, // int n, 
                0.0, // float alpha, 
                array_a, // const float* x, 
                1, // int incx, 
                0.0, // float beta,
                array_b, // const float* y, 
                1, // int incy, 
                results // float* r
        );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  14. #14
    Registered User
    Join Date
    Nov 2003
    Posts
    16
    I am not understanding your call :

    void c_sdot(conj,
    3, // int n,
    0.0, // float alpha,
    array_a, // const float* x,
    1, // int incx,
    0.0, // float beta,
    array_b, // const float* y,
    1, // int incy,
    results // float* r
    );

  15. #15
    Registered User
    Join Date
    Nov 2003
    Posts
    16
    this attachment may help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How Can I draw What I want?
    By CChakra in forum Game Programming
    Replies: 22
    Last Post: 09-11-2008, 08:38 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. need help making a dot bounce up and down y axis in this prog
    By redwing26 in forum Game Programming
    Replies: 10
    Last Post: 08-05-2006, 12:48 PM
  4. Dot Product.......Help
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-07-2003, 08:49 AM