CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 50

Thread: Problem with cmath/gsl

  1. #31
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,265

    Re: Problem with cmath/gsl

    What that prescription on mrcata website was for when we have ready to use VS2015 dll and lib files.
    Yes. From the mrcdata site, download the gsl zip file for VS2015 (click on VS2015 where it says Download The GSL binaries). Then unzip to the suggested VSGSL folder (or any other folder you want - in the instructions just change the vsgsl folder to to the one used). Within that, you should have 3 folders:

    dll
    include
    lib

    include has the #include files

    The dll and lib folders then have a further 4 folders each:
    x64_debug - for 64 bit debug mode
    x64_release - for 64 bit release mode
    x86_debug - for 32 bit debug mode
    x86_release - for 32 bit release mode

    The dll folders have:

    cblas.dll and gsl.dll files

    The lib folders have:

    cblas.lib and gsl.lib files

    Which ones to use depend upon whether you are compiling for 64 bit debug/release or 32 bit debug/release.

    Once you have these folders/files on your computer, then follow the instructions on the mrcata web site for configuring VS to compile using gsl. You should be able to get the program in post #18 to compile, link and run.

    Using the gsl/cblas .dll and .lib files within a C/C++ VS environment is just the same as using any other .lib/.dll file. All you need to do is to set the folder for the include files, the folder for the .lib files and the .lib files to use.

    Note when you come to run the generated programs, the appropriate .dll files need to be found on the search path so that they can be found.

    Note that these .lib & .dll files are for GSL 1.16 (July 2013) - NOT the latest 2.6 version (August 2019). So any required gsl functionality added since 1.16 won't be available.

    The attached is the zip file for my gsltest VS solution. Note that my .dll/.lib files are in c:\develop\vsgsl instead of c:\vsgsl. This was compiled as release/x86.

    gsltest.zip
    Last edited by 2kaud; July 25th, 2020 at 11:57 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  2. #32
    Join Date
    Jul 2020
    Posts
    24

    Re: Problem with cmath/gsl

    Thank you very much for your explanations, everything is clear and works within MSVC environment.
    However, when use the mex wrapper from Matlab environment it seems that the MSVC compiler attached to Matlab environment does not see any settings introduced in MSVC environment, i.e. the pathnames to .lib files.

    So, I manually added the .lib files to some mex compilation lines in Matlab where the libraries were required.
    Some mex compilation lines required one .lib file, some compilation lines required two .lib files (dynamic and static ?), i.e. those used .lib files are as follows:
    '…\STAToolkit\spike\MRCGSL\VS2015\dll\x64_debug\gsl.lib'
    '…\STAToolkit\spike\MRCGSL\VS2015\lib\x64_debug\gsl.lib'
    The complete mex compilation lines (with numbers from 30 to 56) are in file: …\STAToolkit\spike\make_g_debug_x64.m

    Unfortunately, two lines (marked with letter ‘X’ nr 36 and 37) generate linking errors like below, it looks that we have conflicting definitions of functions somewhere. Just in case I tested it also for x64_release option.
    Could I ask you to help to remove that linking error. Thanks.
    All files attached.
    Attached Files Attached Files

  3. #33
    Join Date
    Jul 2020
    Posts
    24

    Re: Problem with cmath/gsl

    I must be doing something wrong with the linking of the gsl libraries in Matlab environment, because even the compilation/linking and building of the mexw64 files went smooth, later, when try to call the mexw64 files from Matlab, the Matlab cannot execute them.

    Invalid MEX-file ……..\STAToolkit\spike\binlessinfo.mexw64': The specified module could not be found.

    It applies to compilation lines 33 36 37 43 44 45 52 53 54 55 56 in …\STAToolkit\spike\make_g_debug_x64.m, where the gsl libraries were attached at the end. As I mentioned in my previous post, the lines marked with letter ‘X’ nr 36 and 37 cannot even be linked using mex in Matlab.

    Please use the 'spike' software from post #32, because the ....spike\gsl contains now header files from VS2015. Thank you.

  4. #34
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,265

    Re: Problem with cmath/gsl

    '…\STAToolkit\spike\MRCGSL\VS2015\dll\x64_debug\gsl.lib'
    '…\STAToolkit\spike\MRCGSL\VS2015\lib\x64_debug\gsl.lib'
    Using a gsl.lib file from a dll folder looks wrong - especially when you are also using gsl.lib file from the lib folder.

    You might also need to use cblas.lib as well. One of the test examples I used in VS needed this .lib file as well as gsl.lib

    For the downloaded mrcata files, I used the .lib files from the appropriate lib folder and the .dll files from the appropriate .dll folder. The dll folders also have .lib files, but I didn't use them.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  5. #35
    Join Date
    Jul 2020
    Posts
    24

    Re: Problem with cmath/gsl

    Thanks. Do you know how to properly build the mexw64 files with that required .lib and .dll files?
    Can you let me know which examples you had to compile with cblas.lib ? Maybe you could attach your compiling mex lines then I could try them on my side.
    Can you create mexw64 file from MSVC ?

  6. #36
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,265

    Re: Problem with cmath/gsl

    I only compiled examples within VS - not mex. The example that required cblas.lib was your example from post #18 - as per the attached zip in post #31.

    I know nothing about mex/matlab - and can't offer any help.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  7. #37
    Join Date
    Jul 2020
    Posts
    24

    Re: Problem with cmath/gsl

    I think I sorted out the mex compilation problem, I have just added two correct libraries to mex lines as below.
    …\spike\MRCGSL\VS2015\lib\x64_debug\gsl.lib
    …\spike\MRCGSL\VS2015\lib\x64_debug\cblas.lib

    I still have a small problem with one C++ file (…\spike\info\metric\metricdist.c); there are problems with allocating/reading memory by variable ‘d_in’ which at the initialisation ‘***d_in’ is described as <unable to read memory>. Later, in line 217, that variable crashes the program. There are also other variables described in the same way i.e. ‘counts’, ‘d_dims’, ‘times’.
    I would be very grateful for correcting these problems, because I was not successful. Thanks.
    Attached Images Attached Images  
    Attached Files Attached Files

  8. #38
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,265

    Re: Problem with cmath/gsl

    The attached image is unreadable!

    d_in is initialised with the result of the call to mxMatrix3Double() on line 182. Any value of d_in prior to line 182 is random, but as it's value isn't used until after it is initialised this isn't a problem. What's the value of d_in on line 185?

    times is initialised with the result of the call to mxCalloc() in line 137. The same applies as per d_in. Also the other variables you mention are initialised from a function returned memory address.

    Note that in c/c++, no POD variable is initialised when it is defined. It is set to a random value. So its value before it is initialised can be anything!

    If the program fails on line 217, then you'll need to debug to determine the cause.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  9. #39
    Join Date
    Jul 2020
    Posts
    24

    Re: Problem with cmath/gsl

    Sorry, I made a mistake, variable 'd' makes error in line 217.
    <Unable to read memory>

  10. #40
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,265

    Re: Problem with cmath/gsl

    Are you compiling as 32 or 64 bit? If 64, have you tried compiling/running as 32 bit?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  11. #41
    Join Date
    Jul 2020
    Posts
    24

    Re: Problem with cmath/gsl

    I compiled everything as 64 bit and would prefer 64 bit as all modern machines are like that and the calculations should perform faster.
    Would you suggest to use 32 bit compilation.

  12. #42
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,265

    Re: Problem with cmath/gsl

    If you are having memory allocation/access issues, then I would try compiling for 32 bit. Not all 32 bit code compiles/executes properly for 64 bit without changes.

    Also, are you compiling/linking with the same - either all 64 bit or all 32 bit? There are 32 bit and 64 bit versions of the .lib/.dll gsl libraries. Everything has to match.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  13. #43
    Join Date
    Jul 2020
    Posts
    24

    Re: Problem with cmath/gsl

    I compile everything with x64 .lib files, so there is a proper matching.

    Will the calculations slow down when compile it with x86 libraries ?
    ------------------------------------------------------------------------------------------

    The problem is caused by this part of the software I think, where e.g.
    P_total = 80
    d_dims = 80
    mxDOUBLE_CLASS = mxDOUBLE_CLASS (6)
    mxREAL (0) this should force real numbers
    (*opts).num_q = 13

    /* Allocate memory for d */
    d_dims = (int *)mxMalloc(3*sizeof(int));
    d_dims[0] = P_total;
    d_dims[1] = P_total;
    d_dims[2] = (*opts).num_q;
    plhs[0] = mxCreateNumericArray(3,d_dims,mxDOUBLE_CLASS,mxREAL);
    d = mxGetPr(plhs[0]);

    The function 'mxCreateNumericArray' requires 'matrix.h', so tried with it as well, but did not help.
    Could you maybe try this piece of code at your machine to see whether you get the same error.

  14. #44
    Join Date
    Jul 2020
    Posts
    24

    Re: Problem with cmath/gsl

    It is the error from MSVC:
    Exception thrown at 0x00007FFD1B2E22E5 (metricdist.mexw64) in MATLAB.exe: 0xC0000005: Access violation writing location 0x0000000000000001.

    It is the error from Matlab:
    Requested 343597383760x13x1522250158000 (17179869184.0GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and
    cause MATLAB to become unresponsive.
    Error in metric (line 104)
    [d,opts] = metricdist(X.N,times,labels,opts);
    Error in demo_metric (line 72)
    [out,opts_used] = metric(X,opts);

    That number (17179869184.0GB) is not random, always the same.

  15. #45
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,265

    Re: Problem with cmath/gsl

    You're going to have to debug the code to see where is the problem.

    What happens when you compile for 32 bit?

    If it runs OK for 32 bit, then I suspect you have an allocation error somewhere. This is sometimes caused by allocation using a multiplier of say sizeof(int) rather than sizeof(*int) etc when allocating memory for pointers. For 32 bits, int and *int are the same size. On 64 bits, int is 32 bit and *int is 64 bit.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

Page 3 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)