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

How to use Nonlinear Least Squares Problem without Constraints

jeremy_74
Beginner
5,206 Views
Hi together,

I'm quite new with using the MKL and also not a big mathematic freak. At the moment I try to solve a Function from the type:

ai + bi * x1 = ci * x2 / (di + x3)

x1, x2, x3 are unknown, I have initial estimations for x2 and x3.

Now the questions:
1.) Can I even use the MKL for that, espacially the strnlsp* functiopns?
2.) in the init function how can I match these function to the transfer parameters and what the... is the length of an function m ?

I found some examples, but those are not really good documented - so I really need your help.

Addition: You can not offend me my critizies my knowledge at mathematic.... ;-)

Thanks for your best effort.
0 Kudos
29 Replies
jeremy_74
Beginner
1,381 Views
We test the program on an second PC - with the same bad result. This PC has an Intel Pentium Dual T3200 CPU. So it seems to depend to other things..
0 Kudos
Gennady_F_Intel
Moderator
1,381 Views
need more details like these:
- OS
- MKL version
- is it 32 or 64 bit?
- the linking line
0 Kudos
jeremy_74
Beginner
1,381 Views
Which Libs do you include? Could it be, that we have to search the reason in the Makefile?

This is my Makefile:
[bash]#############################################################################
# Makefile for building: test
# Generated by qmake (2.01a) (Qt 4.7.1) on: Do. Feb 10 09:10:03 2011
# Project:  test.pro
# Template: app
# Command: /usr/local/Trolltech/Qt-4.7.1/bin/qmake -o Makefile test.pro
#############################################################################

####### Compiler, tools and options

CC            = gcc
CXX           = g++
DEFINES       = -DQT_GUI_LIB -DQT_CORE_LIB
CFLAGS        = -pipe -O2 -D_REENTRANT $(DEFINES)
CXXFLAGS      = -pipe -O2 -D_REENTRANT $(DEFINES)
INCPATH       = -I/usr/local/Trolltech/Qt-4.7.1/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.7.1/include/QtCore -I/usr/local/Trolltech/Qt-4.7.1/include/QtGui -I/usr/local/Trolltech/Qt-4.7.1/include -I/opt/intel/composerxe-2011.2.137/mkl/include -I.
LINK          = g++
LFLAGS        = -Wl,-O1 -Wl,-rpath,/usr/local/Trolltech/Qt-4.7.1/lib
LIBS          = $(SUBLIBS)  -L/usr/local/Trolltech/Qt-4.7.1/lib -L/opt/intel/lib/ia32 -L/opt/intel/ipp/lib/ia32 -L/opt/intel/composerxe-2011.1.107/ipp/lib/ia32 -liomp5 -L/opt/intel/mkl/lib/ia32 -lmkl_sequential -lmkl_core -lmkl_def -lmkl_solver -lmkl_avx -lmkl_gf -lmkl_gnu_thread -mkl_intel_thread -lmkl_intel -lmkl_p4 -lmkl_p4m -lmkl_p4m3 -lmkl_p4p -lmkl_rt -lQtGui -lQtCore -lpthread 
AR            = ar cqs
RANLIB        = 
QMAKE         = /usr/local/Trolltech/Qt-4.7.1/bin/qmake
TAR           = tar -cf
COMPRESS      = gzip -9f
COPY          = cp -f
SED           = sed
COPY_FILE     = $(COPY)
COPY_DIR      = $(COPY) -r
STRIP         = strip
INSTALL_FILE  = install -m 644 -p
INSTALL_DIR   = $(COPY_DIR)
INSTALL_PROGRAM = install -m 755 -p
DEL_FILE      = rm -f
SYMLINK       = ln -f -s
DEL_DIR       = rmdir
MOVE          = mv -f
CHK_DIR_EXISTS= test -d
MKDIR         = mkdir -p

####### Output directory

OBJECTS_DIR   = ./

####### Files

SOURCES       = test.cpp 
OBJECTS       = test.o
DIST          = /usr/local/Trolltech/Qt-4.7.1/mkspecs/common/g++.conf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/common/unix.conf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/common/linux.conf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/qconfig.pri 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/modules/qt_webkit_version.pri 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/qt_functions.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/qt_config.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/exclusive_builds.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/default_pre.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/release.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/default_post.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/qt.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/unix/thread.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/moc.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/include_source_dir.prf 
		test.pro
QMAKE_TARGET  = test
DESTDIR       = 
TARGET        = test

first: all
####### Implicit rules

.SUFFIXES: .o .c .cpp .cc .cxx .C

.cpp.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.cc.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.cxx.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.C.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.c.o:
	$(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"

####### Build rules

all: Makefile $(TARGET)

$(TARGET):  $(OBJECTS)  
	$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)

Makefile: test.pro  /usr/local/Trolltech/Qt-4.7.1/mkspecs/linux-g++/qmake.conf /usr/local/Trolltech/Qt-4.7.1/mkspecs/common/g++.conf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/common/unix.conf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/common/linux.conf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/qconfig.pri 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/modules/qt_webkit_version.pri 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/qt_functions.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/qt_config.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/exclusive_builds.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/default_pre.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/release.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/default_post.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/qt.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/unix/thread.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/moc.prf 
		/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/include_source_dir.prf
	$(QMAKE) -o Makefile test.pro
/usr/local/Trolltech/Qt-4.7.1/mkspecs/common/g++.conf:
/usr/local/Trolltech/Qt-4.7.1/mkspecs/common/unix.conf:
/usr/local/Trolltech/Qt-4.7.1/mkspecs/common/linux.conf:
/usr/local/Trolltech/Qt-4.7.1/mkspecs/qconfig.pri:
/usr/local/Trolltech/Qt-4.7.1/mkspecs/modules/qt_webkit_version.pri:
/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/qt_functions.prf:
/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/qt_config.prf:
/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/exclusive_builds.prf:
/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/default_pre.prf:
/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/release.prf:
/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/default_post.prf:
/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/qt.prf:
/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/unix/thread.prf:
/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/moc.prf:
/usr/local/Trolltech/Qt-4.7.1/mkspecs/features/include_source_dir.prf:
qmake:  FORCE
	@$(QMAKE) -o Makefile test.pro

dist: 
	@$(CHK_DIR_EXISTS) .tmp/test1.0.0 || $(MKDIR) .tmp/test1.0.0 
	$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/test1.0.0/ && $(COPY_FILE) --parents test.cpp .tmp/test1.0.0/ && (cd `dirname .tmp/test1.0.0` && $(TAR) test1.0.0.tar test1.0.0 && $(COMPRESS) test1.0.0.tar) && $(MOVE) `dirname .tmp/test1.0.0`/test1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/test1.0.0


clean:compiler_clean 
	-$(DEL_FILE) $(OBJECTS)
	-$(DEL_FILE) *~ core *.core


####### Sub-libraries

distclean: clean
	-$(DEL_FILE) $(TARGET) 
	-$(DEL_FILE) Makefile


check: first

/usr/local/Trolltech/Qt-4.7.1/bin/moc:
	(cd $(QTDIR)/src/tools/moc && $(MAKE))

mocclean: compiler_moc_header_clean compiler_moc_source_clean

mocables: compiler_moc_header_make_all compiler_moc_source_make_all

compiler_moc_header_make_all:
compiler_moc_header_clean:
compiler_moc_source_make_all:
compiler_moc_source_clean:
compiler_clean: 

####### Compile

test.o: test.cpp 
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o test.o test.cpp

####### Install

install:   FORCE

uninstall:   FORCE

FORCE:
[/bash]
0 Kudos
jeremy_74
Beginner
1,381 Views
- Ubuntu 10.10
- MKL 10.3.2.137
- 32 Bit
- what you are asking for with linking line? - All the LIBS? If yes see the provided makefile..
0 Kudos
Gennady_F_Intel
Moderator
1,381 Views
smth like that:
-Wl,--start-group $MKLroot/libmkl_intel.a $MKLroot/libmkl_intel_thread.a $MKLroot/libmkl_core.a -Wl,--end-group -openmp -lpthread
0 Kudos
jeremy_74
Beginner
1,381 Views
LFLAGS=-Wl,-O1-Wl,-rpath,/usr/local/Trolltech/Qt-4.7.1/lib
LIBS=$(SUBLIBS)-L/usr/local/Trolltech/Qt-4.7.1/lib-L/opt/intel/lib/ia32-L/opt/intel/ipp/lib/ia32-L/opt/intel/composerxe-2011.1.107/ipp/lib/ia32-liomp5-L/opt/intel/mkl/lib/ia32-lmkl_sequential-lmkl_core-lmkl_def-lmkl_solver-lmkl_avx-lmkl_gf-lmkl_gnu_thread-mkl_intel_thread-lmkl_intel-lmkl_p4-lmkl_p4m-lmkl_p4m3-lmkl_p4p-lmkl_rt-lQtGui-lQtCore-lpthread
0 Kudos
Gennady_F_Intel
Moderator
1,381 Views
Please try to relink accordingly the linker adviser suggestion.
0 Kudos
mecej4
Honored Contributor III
1,381 Views
I ran your code from #18 on Win7-X64 using Intel C 11.1.065 (64 bit) and the bundled MKL, compiling with the command

S:\MKL> icl /Qmkl nlfit.cpp

The program ran to completion with no error messages on a laptop with 4GB of RAM and a dual core Intel T4300.

It would help if you compiled with the -g option and ran the code under GDB, if only to determine whether the illegal instruction is generated from your code or is in the C++ runtime or the MKL library code.
0 Kudos
jeremy_74
Beginner
1,381 Views
Thank you very very much.....

The reason was the wrong usage of the embedded Librarries!! Thank you for this information. Everythings work now like it should....
0 Kudos
Reply