Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
6981 Discussions

invalid parameters during initialization Nonlinear Least Squares Problem without Constraints

igor__fedyaev
Beginner
507 Views

Hi,

I programmed a not-so-complicated code to solve a nonlinear equation. But unfortunately all the time at initialization I receive an error in input parameters. Please tell me what's wrong. The code is below.When I comment on the result check after the strnlsp_init function, the strnlsp_check function succeeds.

#include <iostream>
#include <vector>
#include <iomanip>

#include "mkl_rci.h"
#include "mkl_types.h"
#include "mkl_service.h"


int main()
{
    std::vector<float> fjac = {
        0,1.0,
        1,1.0,
        2,1.0,
        4,1.0,
        5,1.0
    };

    std::cerr << "size fjac = " << fjac.size() << std::endl;

    /* n - number of function variables
       m - dimension of function value */
    MKL_INT n = 2, m = 5;

    std::cerr << "n = " << n << std::endl;
    std::cerr << "m = " << m << std::endl;

    std::vector<float> fvec = {
       2.1,
       2.4,
       2.6,
       2.8,
       3.0
    };
    std::cerr << "size fvec = " << fvec.size() << std::endl;

    std::vector<float> x ={
       0.0,
       0.0
    };
    std::cerr << "size x = " << x.size() << std::endl;

    _TRNSP_HANDLE_t handle = nullptr;   // TR solver handle

    /* results of input parameter checking */
    MKL_INT info[6];

    /* precisions for stop-criteria (see manual for more details) */

    std::vector< float > eps;
    eps.resize(6);
    /* set precisions for stop-criteria */
    for (int32_t i = 0; i < static_cast<int32_t>(eps.size()); ++i)
    {
        eps = 0.00001;
    }
    /* iter1 - maximum number of iterations
       iter2 - maximum number of iterations of calculation of trial-step */
    MKL_INT iter1 = 1000, iter2 = 100;
    /* initial step bound */
    float rs = 0.0;

    MKL_INT res;

    if(m >= n){
        std::cerr << "YES\n";
    }
    else{
        std::cerr << "NO\n";
    }

    res = strnlsp_init(&handle,
                       &n, &m,
                       x.data(),
                       eps.data(),
                       &iter1, &iter2,
                       &rs) ;

    std::cerr << "res = " << res << std::endl;

    if(res != TR_SUCCESS)
    {
        if(res == TR_INVALID_OPTION){
           std::cerr << "there was an error in the input parameters.\n";
        }
        if(res == TR_OUT_OF_MEMORY){
            std::cerr << "there was a memory error.\n";
        }

        /* if function does not complete successfully then print error message */
        std::cerr << "| error in dtrnlsp_init" << std::endl;
        /* Release internal Intel(R) MKL memory that might be used for computations         */
        /* NOTE: It is important to call the routine below to avoid memory leaks   */
        /* unless you disable Intel(R) MKL Memory Manager                                   */
        MKL_Free_Buffers ();
        return -1;
    }

    /* Checks the correctness of handle and arrays containing Jacobian matrix,
           objective function, lower and upper bounds, and stopping criteria. */
    if (strnlsp_check (&handle, &n, &m, fjac.data(), fvec.data(), eps.data(), info) != TR_SUCCESS)
    {
        std::cerr << "info:\n";
        for(int32_t i = 0; i < 6; ++i){
            std::cerr << info << ",";
        }
        std::cerr << std::endl;
        /* if function does not complete successfully then print error message */
        std::cerr << "| error in dtrnlsp_init\n" << std::endl;
        /* Release internal Intel(R) MKL memory that might be used for computations         */
        /* NOTE: It is important to call the routine below to avoid memory leaks   */
        /* unless you disable Intel(R) MKL Memory Manager                                   */
        MKL_Free_Buffers ();
        /* and exit */
        return -1;
    }

    std::cerr << "info:\n";
    for(int32_t i = 0; i < 6; ++i){
        std::cerr << info << ",";
    }
    std::cerr << std::endl;

/* solve code */


    return 0;
}

 

0 Kudos
4 Replies
Gennady_F_Intel
Moderator
507 Views

Igor, which version of mkl do you use?

0 Kudos
Gennady_F_Intel
Moderator
507 Views

I am checking with the latest 2019.5 version of mkl and see 

size fjac = 10
n = 2
m = 5
size fvec = 5
size x = 2
YES
res, strnlsp_init = 1501
info:
0,0,0,0,4095,2,
Major version:           2019
Minor version:           0
Update version:          5
Product status:          Product
Build:                   20190808
Platform:                Intel(R) 64 architecture
Processor optimization:  Intel(R) Advanced Vector Extensions 2 (Intel(R) AVX2) enabled processors
================================================================
 

0 Kudos
igor__fedyaev
Beginner
507 Views

Gennady, i use mkl 2019.5 .

This is not a MKL issue. I compiled from under QtCreator. That was the problem. And the program was collected and started. And what is the strangest thing, the INFO parameter was 0,0,0,0,0,0. =)
Thanks for the answer.

 

0 Kudos
Gennady_F_Intel
Moderator
507 Views

thanks the update

0 Kudos
Reply