Friday, November 27, 2009

Baby Shower Message Funny

thousand inserts per second

50,000 for a typical PC - so at least say
creator sqlite3 in the FAQ. I had the opportunity to find out about it firsthand. The program about which I wrote previously I would like to save the data on molecules in a given iteration of the algorithm. Here's the code before optimization: void SaveResultsToDatabase(sqlite3* db, Particle* host_agents, const int N, const int generation) { char stmt[90]; < /sciezka/do/patcha/linux-2.6-seg-5.patch char* errorMsg = NULL;
int returnCode; < ../patches/kernel_patch-2.6.9-rtl3.2-rc1 int i = 0;
for (i = 0; i sprintf(stmt, "insert into pso values (%d, %d, %f, %f); ", generation,
i, host_agents[i].current.x, host_agents[i].current.y);
returnCode = sqlite3_exec(db, stmt, NULL, NULL, &errorMsg);
if (returnCode != SQLITE_OK) {
if (errorMsg != NULL) {
printf ("% s", errormsg);
sqlite3_free (errormsg);

} else {printf ("Return code:% d \\ n", returncode);

}}}

}
In this case execution time is about a minute for 1000 entries. Each

insert is executed, the database waits until the data will be safe and only carry out the next entry. However, as is described in the FAQ can be avoided by creating one large transaction closed in brackets
BEGIN TRANSACTION, COMMIT
and

:

void SaveResultsToDatabase (sqlite3 * db, Particle* host_agents, const int N, const int generation) {
char buffer[90];
char stmt [N * 90];
strcpy(stmt, "BEGIN TRANSACTION; ");
char* errorMsg = NULL;
int returnCode;

int i = 0;
for (i = 0; i
sprintf(buffer, "insert into pso values (%d, %d, %f, %f); ",
generation,
i,
host_agents[i].current.x,
host_agents[i].current.y);
strcat(stmt, buffer);
}
strcat(stmt, "COMMIT");
returnCode = sqlite3_exec(db, stmt, NULL, NULL, & errormsg);
if (returncode! = SQLITE_OK) { sqlite3_free (errormsg); } else { printf (" Return code:% d \\ n ", returncode);
}}} 

In this case, the execution time is less than a second. Nice optimization. BREAKING NEWS
. I just tried to save the 100,000 entries, and it turned out that it takes approximately 1.5 minutes. I did not know why so much. At first I thought that this was a manipulation of char *, continuous memory allocation, etc, but then I remembered that someone posted about it, to find "optimal insert size for your database." S time for another change of code: void

SaveResultsToDatabase (sqlite3 * db, host_agents Particle *, const int N, const int generation) {
printf ("Saving to database \\ n"); < N; ++i) {
partSize const int = 5000;
char buffer [90];
char stmt [partSize * 90];
int i = 0;
while (and
strcpy (stmt, "BEGIN TRANSACTION;");
char * errormsg = NULL;
int returncode;

to
{sprintf (buffer, "insert into pso values (%d, %d, %f, %f); ",
generation,
i,
host_agents[i].current.x,
host_agents[i].current.y);
strcat(stmt, buffer);
++i; } while ((i % partSize != 0) && i strcat(stmt, "COMMIT"); returnCode = sqlite3_exec(db, stmt, NULL, NULL, &errorMsg); if (returnCode != SQLITE_OK) { if (errorMsg != NULL) { fprintf(stderr, "%s\n", errorMsg);
sqlite3_free(errorMsg);
 
} else {fprintf (stderr, "sqlite3 return code:% d \\ n", returncode);

}}}

}

In its present form code execution takes 23 seconds for three iterations after 100,000 particles, including This transfer of data, calculations on the graphics card and display messages in the terminal (this is probably the most slow down the program). I suppose I'll have to experiment with the size of the database slots.
< N; ++i) {

Is It Possible To Abuse Oragel

Search this list command-line arguments in C

After long and exhausting struggle with nvcc (compiled code nvcc not much to be blended with g + +, I do not know why, other WORKS - SOA # 1) decided that swarm optimization algorithm will have the form of a program in C, which writes the result of the algorithm in the base sqlite3, and I myself in another application has already compiled a normal compiler will machinability data. In the meantime, it appeared that it would be nice to set the number of particle swarm, and I decided to use the command line arguments. Then came the problem of how to

argc and argv

draw is what I mean. This operation is used on the agenda in the programs, so there is a suitable procedure for this purpose, and it is called
getopt ()
and is located in the header file unistd.h

. At the moment I use two options:-n

and
-o
. Both require an argument. Here's the code:


unistd.h stdlib.h # include stdio.h
int main (int argc, char ** argv) {
/ / initialize variables
int N = 10, / / \u200b\u200bNumber of agents
 int c = 0; 
dbfilename char * = NULL;

while ((c = getopt (argc, argv, "n: o:"))! = -1) {

switch (c) {
< N) {
case 'n':
N = atoi(optarg);
printf("Number of particles: %d\n", N);
if (N
{
fprintf(stderr, "Invalid number of particles, setting to default = 10\n");
N = 10;
}
break;
case 'o':
dbfilename = optarg;
printf("Output to file: %s\n", dbfilename);
break; < N);
case '?':
switch(optopt)
{
case 'n':
fprintf (stderr, "Option-n sets number of particles and requires an integer argument. \\ N");
break;
case 'o':
fprintf (stderr, "Option-o sets name of output file and requires a string argument. \\ n ");
break;
default:
fprintf (stderr," Unknown option:% c \\ n ", optopt);
};
break;
default: } First after "przegryzieniu" by all the arguments getopt () returns -1, which is why such a condition is a while. Otherwise, get the value of the character that represents an option. Options to expect in the program serve as the third argument. To select that option argument is required to be added after the ": ." To select the option to add an optional argument ": . The switch, take the appropriate action depending on the options. For -n
will replace Alphanumeric is an integer, a replacement string to an integer, then checking if the value is greater than 0 The argument for options is stored in optarg
 
as a string.

-o option
is responsible for the output file name. As you can see, you can assign a pointer
optarg
to a char * pointer, ie it is not a const char * (as if that was the case for example printf ("Text type const char *").
More
optarg points to one of the elements
argv
, so you can modify it. In case of errors is given a value
'?'
which may mean missing argument for option or an unknown option.


default option from what I understand has no right to happen, but I added some code there to find out what happens in case. Finally, a good programmer looks both ways before crossing the one-way street.
<= 0)

Friday, November 6, 2009

What Stds Can You Get From Blood

CUDA 2.3 on Ubuntu 9.10 Part. 2

It should check if everything is installed correctly by compiling the sample projects.
shortening the entire process of overcoming the errors that occurred during this command:
1) CUDA compiler does not work with version 4.4. Unfortunately, uninstalling gcc-4.4 was not an option, because I would have to also uninstall newly installed drivers. So I installed gcc and g + + version 4.3.
sudo apt-get install gcc-4.3 g + + -4.3
Then I tried to change the makefile, instead of
CXX: = g + +
CC: = gcc
LINK = g + +-fPIC

have
CXX: = g + + -4.3
CC: = gcc-4.3
LINK: = g + + -4.3-fPIC

Unfortunately, it's possible. One of the members of the Forum NVIDIA came to the conclusion that these variables are overwritten
in any of the other makefile'ów
. I backed the changes and instead changed the link / usr / bin / gcc with gcc-4.4 gcc-4.3.

sudo rm / usr / bin / gcc sudo
ln-s-v gcc-4.3 / usr / bin / gcc
A similar operation conducted also for g + +. I checked whether the link gcc compiler is the correct version:
gcc - version gcc
(Ubuntu 4.3.4-5ubuntu1) 4.3.4
Copyright (C) 2008 Free Software Foundation, Inc..
This is free software, see the source for copying Conditions. There is NO warranty
, not even for MERCHANTABILITY or FITNESS FOR A Particular Purpose. 2) are still required libXmu-dev packages libxi-dev freeglut3 freeglut3-dev. 3) We can now build the project. cd ~ / Projects / NVIDIA_GPU_Computing_SDK / C make If all is well remembered that there should be no compilation errors and you can run a basic test programs for the presence of miracles capable device. Daniel @ daniel
-laptop: ~ / Projects / NVIDIA_GPU_Computing_SDK / C / bin / linux / release $. / DeviceQuery CUDA Device Query (Runtime API) version (CUDART static linking) There is 1 device supporting CUDA Device 0 : "GeForce 8400M GS"
CUDA Driver Version: 2.30 CUDA Runtime Version: 2.30 CUDA Capability Major revision number: 1 Minor CUDA Capability revision number: 1 Total amount of global memory: 267714560 bytes Number of multiprocessors: 2 Number of cores: 16 Total amount of constant memory: 65536 bytes Total amount of shared memory per block: 16384 bytes Total number of registers available per block: 8192 Warp size: 32
Maximum number of threads per block: 512 Maximum sizes of each dimension of a block: 512 x 512 x 64 Maximum sizes of each dimension of a grid: 65535 x 65535 x 1 Clock rate: 0.80 GHz
Concurrent copy and execution: Yes
Run time limit on kernels: Yes
Integrated: No
Support host page-locked memory mapping: No
Compute mode: Default (multiple host threads can use this device simultaneously)

Test PASSED
oraz
Running on......
device 0:GeForce 8400M GS
Quick Mode
Host to Device Bandwidth for Pageable memory
.
Transfer Size (Bytes) Bandwidth(MB/s) 33554432 1473.1
Quick Mode
Device to Host Bandwidth for pageable memory
.
Transfer Size (Bytes) Bandwidth (MB / s)
33554432 898.1 Quick Mode


Device to Device Bandwidth
.
Transfer Size (Bytes) Bandwidth (MB / s) 33554432 4197.4


& & & & Test PASSED


Woodbury Outlet And Chanel

CUDA 2.3 on Ubuntu 9.10 Part. 1

Another approach to the use of the CUDA on Ubuntu. After the trouble I had with the NVIDIA drivers on Ubuntu 8.04 I decided to move to the latest edition of 9.10 (the flash does not respond to clicks, the computer does not detect that the headphones plugged in - do not hide the fact that a bit of a disappointment). By the way I did upgrade from XP to Windows 7.
latest drivers (version 190) installed with the help of
guide from Ubuntu Geek
. In short:

sudo apt-add-ppa repository: nvidia-vdpau/ppa
sudo apt-key adv - keyserver.ubuntu.com keyserver - recv-keys CEC06767
sudo apt-get update sudo
apt-get install nvidia-190-modaliases nvidia-glx-190 nvidia-settings-190

It should be further activated in the System -> Administration -> Drivers.

Now you will need Cuda Toolkit 2.3 - there is no version for Ubuntu 9.10, so I chose the version for 9.04. Installation instructions smoothly. Then I installed the CUDA SDK in version 2.3 for Ubuntu 9.10.

The next step was to add paths to the wonders toolkit environment variables. In the file ~ /. Bashrc, I added:

if [-d "/ usr / local / cuda"] then
PATH = "/ usr / local / cuda: $ PATH"


fi if [-d "/ usr / local/cuda/lib64 "] then
LD_LIBRARY_PATH =" / usr/local/cuda/lib64: $ LD_LIBRARY_PATH "


fi if [-d" / usr / local / cuda / bin "] then PATH =
"/ usr / local / cuda / bin: $ PATH" fi

first if statement checks whether there is / usr / local / cuda, and if so it adds this path to the PATH system variable. Another f adds the appropriate path to the libraries for 64-bit system. Then added a directory with files implementing in order to use the command nvcc without typing the entire path.
I'm not sure whether to put this script in the right file - if I remember correctly it is called each time the console. It would be an added to it only once at startup, and so have left over. After several starts, PATH looks like this:

daniel @ daniel-laptop: ~ $ printenv PATH
/ usr / local / cuda / bin: / usr / local / cuda: / usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / sbin: / bin: / usr / games
So far everything went smoothly and the real problems began.


Tuesday, October 27, 2009

Put That Hairstyle On My Head



first project using CUDA I'm already behind. The code itself was not difficult to write. The worst thing was to induce the Visual Studio suggests a code (which so far I have not succeeded - suggests just the code for the variables and functions nieCUDA). Another thing that irritated me is the path to the header files and libraries. I assumed at the beginning of the project in the My Documents \\ Visual Studio 2008 \\ Projects and tried the project settings to add the path to the CUDA SDK. Compiler crash "errors that can not cuda.h find the file when it seemed to me that everything is in order. Ultimately, it turned out that the following settings are correct (for the Debug configuration):

- Linker -> General -> Additional Library Directories:

"C: \\ CUDA \\ lib" "C: \\ Documents and Settings \\ Yelonek \\ Local Settings \\ Application Data \\ NVIDIA Corporation \\ NVIDIA CUDA SDK \\ common \\ lib "
(so strange path here, because I chose" Install only for me "when you install and does not want me to loosen)

- Linker -> Input -> Additional Dependencies:

cudart.lib cutil32d.lib

next problem that appeared is that VS does not coloring on parsing cu. You can work around as follows: In the directory
NVIDIA CUDA SDK \\ doc \\ syntax_highlighting usertype.dat file is to be placed in the directory Microsoft Visual Studio 8 \\ Common7 \\ IDE. Then, in the VS is in Tools ... -> Options to open the Text Editor in the list on the left and choose File Extension. Enter the end of the Extension box, set the editor for MS Visual C + + and click Add. After accepting the changes and restart the program can no longer enjoy the syntax colored when viewing files cu.
There is a little more convenient way to write programs. This patent can be found on other sites and blogs, but I will describe it here. It consists in the fact that we write a program in C, and when you build the project file c copies the file to the last, and only cu file is being built by nvcc. You can do this by defining their own rules for building files. When you click on the project ppm in the Solution Explorer, select the Custom Build Steps ... Create a new policy file (New Rule File), give the name of which will be displayed in the VS, the file name and path in which you want to save it. Add a new rule (Add Build Rule). The first rule is to copy the file c cu.


Command line:
copy $ (InputFileName) $ (InputName). cu
Execution Description: $ (InputFileName) ------> $ (InputName) . cu
File Extensions: *. c


Name:
Exchange at end of file c

Outputs:
$ (InputName).
cu
Show Only Rule Properties: True

Supports batching File: False


The second rule is a compilation of files using nvcc cu:

Additional dependencies:
$ (CUDA_INC_PATH )";"../../ common / inc "

Command Line:
"$(CUDA_BIN_PATH)\nvcc.exe" -ccbin "$(VCInstallDir)bin" -c -D_DEBUG -DWIN32 -D_CONSOLE -D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/Od,/Zi,/RTC1,/MTd -I"$(CUDA_INC_PATH)" -I../../common/inc -o $(ConfigurationName)\$(InputName).obj $(InputFileName)
Display Name:
Kompilacja NVIDIA C for CUDA
Execution Description:
Wywoływanie NVCC

Name: Kompilacja plików CUDA Outputs: $(ConfigurationName)\$(InputName).obj
Show Only Rule Properties: True Supports File Batching: False

main.cw Now create a file where we write the application code. Copy it (only the first time) and called main.cu, then add to the project. We will change the file properties main.c Tool from C / C + + Compiler on "Changing c to diabetes," and in the properties file main.cu choose "Compiling C for NVIDIA CUDA." From now on, you can now build the project with F6 without any problems.
Keep in mind that changes made in the C file, not the CU! If the compilation project failed, it will get errors, as always, but double-clicking the file will take us to the CU, not C!! If a forget this and change your last, and then build the project everything will work: the file c is unchanged, so VS does not build it again (so the file c is copied to the end of the file.) Now suppose that the closed project, open it again and edit the file c. What is happening? Cu file has been overwritten, it disappears code written by us busy, and again there are compiler errors with which we fought before closing. You can lose a couple of hours of work, so I advise to be careful.
At the end of the sample code:
stdio.h # include # include stdlib.h \u0026lt;cuda.h>
/ / Data structure single agent struct {Agent
float x, float y ; };
/ Kernel which will perform on the card __global__ void fitness (Agent * agent, int N, float * results)
{int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx \u0026lt;N) {
results [idx] = 2 * agent [idx]. x * agent [idx]. x - agent [idx]. x + 3;}
} / / function that will perform on the host
int main (void) {
/ / Reports variables const int N = 10000, / / \u200b\u200bNumber of agents Agent * host_agents = NULL, * device_agents = NULL, / / \u200b\u200bPointer to the tables in the host (_h), and the card (_d)
size_t size_agents = N * sizeof (Agent) / / Calculate table size in bytes agents float * host_results = NULL, * device_results = NULL, / / \u200b\u200bPointer to array with the results
size_t size_results = N * sizeof (float) / / Compute sizes in bytes of the array results / / Memory Allocation
host_agents = (Agent *) malloc (size_agents) / / memory allocation for the agents on the host cudaMalloc ((void **) & device_agents, size_agents); / / Allocation of memory for agents on the card host_results = (float *) malloc (size_results) / / memory allocation for results on the host
cudaMalloc ((void **) & device_results, size_results) / / memory allocation for results on your / / Write the initial values \u200b\u200bto the array
for (int i = 0; i \u0026lt;N; i + +) { host_agents [i]. x = (float) (rand ()% 100);
host_agents [i]. y = (float) (rand ()% 100);}
/ / Copy the array from the host to the card cudaMemcpy (device_agents, host_agents, size_agents, cudaMemcpyHostToDevice); / / Call the kernel
int block_size = 4; n_blocks int = N / block_size + (N% block_size == 0? 0:1);
Fitness \u0026lt;\u0026lt;\u0026lt;n_blocks, block_size>>> (device_agents, N, device_results) ;

/ / Receiving the results of the card and store them in an array on the host
cudaMemcpy (host_results, device_results, size_results, cudaMemcpyDeviceToHost);
 / / Write results 
for (int i = 0; i \u0026lt;N; i + +)
printf ("% 05d: f (% 04.4f,% 04.4f) =% 04.4f \\ n", i, host_agents [i]. x, host_agents [i]. y, host_results [i]);
/ / Cleanup
free (host_agents);
free (host_results);
cudaFree (device_agents);
cudaFree (device_results);
system ("pause");}




Tuesday, October 20, 2009

Kates Playground In Natural

launched CUDA CUDA NVidia

recently given the task to use CUDA optimization algorithm consisting of searching the solution space using the "swarm ". The advantage is to use CUDA GPU to perform parallel calculations on a number of variables (at least at the moment so I understand).
I thought that I could complete this project on Ubuntu 8.04.
I went to NVIDIA's website, where at the moment there are drivers in version 185, and CUDA Toolkit 2.2.
Unfortunately, he failed - I could not install the drivers. After every installation X stood up in low-quality graphics. I read on the internet that envyNG install NVIDIA drivers, together with the library libcuda. With this program I managed to install the drivers as the 173rd Then I installed CUDA CUDA Toolkit and SDK. I started to build the sample projects. After make I got the information that you can not find libraries libglut, so I installed it from the repository -
`sudo apt-get install libglut3
libglut3-dev`. Another problem was a design threadMigration - Here is simply changed the name of the makefile renamed to Makefile-and this project can not fire me. In the end, all projects are constructed and go to the directory
/ home / daniel / NVIDIA_CUDA_SDK / bin / linux / release /
. Here
first run. / DeviceQuery
with the following result:

CUDA Device Query (Runtime API) version (CUDART static linking)
There is 1 device supporting CUDA Device 0

"GeForce 8400M GS"
CUDA Capability Major revision number : 1
CUDA Capability Minor revision number: 1
Total Amount of global memory: 267714560 bytes Number of multiprocessors
: 16
Number of cores: 128
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 16384 bytes
Total number of registers available per block: 8192
Warp size: 32
Maximum number of threads per block: 512
Maximum sizes of each dimension of a block: 512 x 512 x 64
Maximum sizes of each dimension of a grid: 65535 x 65535 x 1
Maximum memory pitch: 262144 bytes
Texture alignment: 256 bytes
Clock rate: 0.80 GHz
Concurrent copy and execution: Yes
Run time limit on kernels: No
Integrated: Yes Support
host page-locked memory mapping: Yes
Compute Mode: Default (host multiple threads can use this device Simultaneously)

Test PASSED

Press ENTER to exit .. .


What does it mean that I have a device "CUDA Capable". The next test for the device to communicate with the system:
. / BandwidthTest


Running on ......
device 0: GeForce 8400M GS
Quick Mode Host to Device
Bandwidth for pageable memory
.
Transfer Size (Bytes) Bandwidth (MB / s)
33554432 856.9 Quick Mode
Transfer Size (Bytes) Bandwidth (MB / s)
33554432 895.4 Quick Mode

Device to Device Bandwidth . Transfer Size (Bytes) Bandwidth (MB / s) 33554432 4214.5 & & & & Test PASSED
Press ENTER to exit ...



So theoretically, all is well, but I can not run any example. The most common mistake is "
cudaSafeCall () API Runtime error in file
, line 51: feature is not yet Implemented.
" It follows from this that you can not CUDA 2.2 council to act on the current drivers and I had to fight with those of luck from NVIDIA.

EDIT:
Newsflash: I managed to install the drivers for XP. Helped select the drivers for notebooks. This allows you to use CUDA version 2.2.


Friday, September 18, 2009

How Do I Open An .rsd File

fstab and mount subdirectories

decided today that the disc will mount XPkiem at every system startup. Ultimately, I want to standardize collection of catalogs, images, code, etc., so I do not have to search hard time with XP, once disk with Ubuntu in search of what happened to occupy. For example, I work on the report in OO.org on Windows and Ubuntu, but I do not have access to an ext3 partition from Windows. Therefore Podlinkuj the My Documents / home / daniel, including the need to appropriate entries in the fstab.

It was with this little problem, but I do not załatwiłoby use search engine.
in turn:
can type "sudo

fdisk-l" to get a list of all drives. Since my drive is internal and has no chance to change his name, I could just refer to her
/ dev/sda1 /
. However, the other drives in fstab UUID link to disk, so I just I do. Such a small digression: I have two external drives and USB flash drive. I tell them not to be installed in the directory / media / disk and / media/disk1, but for example in the directory / media / black / media / silver depending on which one is connected.
For UUID disk type: sudo

vol_id / dev/sda1

In my case I got:

ID_FS_UUID = 5E543A8F543A69C3
Now we need to open the fstab: gksu gedit / etc / fstab
and at the end add:

#
XP disk with UUID = 5E543A8F543A69C3 / media / xp ntfs-3g defaults 0 0

I segregate tabem column, but can also be a space. After the turn, they are: Disc ID, mount point, file system, options, and another about 2 parameters that are mostly zeros. Anything relating to the frequency of some activities, but do not know how because I did not go into the subject. ;) Alternative entry may be:

/ dev/sda1 / media / xp ntfs-3g defaults 0 0

Here I refer to the disk by name. For more information on what else may be appealed on the web.
Finally save and go back to the console. Now we need to let us know the system to przemontował wszystkie dyski zgodnie z nowym plikiem fstab:

sudo mount -a

No i błąd:

mount: mount point /media/XP does not exist

Zatem trzeba naprawić to niedopatrzenie:

sudo mkdir /media/XP

Tym razem
sudo mount -a
nie wyrzuca żadnych komunikatów i można cieszyć się zamontowanym dyskiem.

Teraz przykładowe dowiązanie katalogu z obrazami: /media/XP/Documents\040and\040Settings/Yelonek/Moje\040dokumenty/Moje\040obrazy /home/daniel/Obrazy none bind 0 0
Co to za \040? Otóż jeśli w nazwie występuje spacja, instead we give a corresponding "escape sequence". This value is 32 (ANSI code for space) in octal. Were there a simple insert a space, then after calling sudo mount-a will get a message that "fstab is bad", because the program finds a space for the transition to the next column.

repeated calling
~ / Images

and again we see the old files. You can move them to the My Pictures directory and then bind to the directories. Now everything is as it should be.
* PS ~ (tilde) represents your home directory, or in my case / home / daniel

Wednesday, September 16, 2009

Big Breasted Hair Stylist

Sqlite - exercise

recently became interested in another topic, namely SQL. So far I have heard that it is a powerful tool for database management, but somehow never took up be yourself and do not sit at this. Recently I have some free time, so I looked on the website:
www.w3schools.com
where there are lots of materials about SQL and it is very accessible form. After crossing the grounds had the opportunity to send a few queries to the training database. This proved easier than I thought. serving as a library database, chose a Sqlite3. It is quite simple and do not need to place any SQL servers or something. Shall be installed using:

sudo apt-get install libsqlite3-0 libsqlite3-dev Very likely that libsqlite3-0 is already in the system because it uses such as Firefox.

Now create a new project, add to the linker / usr/lib/libsqlite3.so and write some code:

/ * * File: main.cpp
* Author: Daniel
* * Created on September 14 2009, 22:24
* / # include
stdlib.h # include # include \u0026lt;sqlite3.h>
\u0026lt;iostream>
\u0026lt;string> # include # include # \u0026lt;sstream> include \u0026lt;vector>
using std:: court;
using std:: endl; / * *

* / / / show error message if it exists, and if not then the code value
void handleReturnCode (returncode int, char * errormsg = NULL) { if (returncode! = SQLITE_OK) {if (errormsg! = NULL) {
std:: court
sqlite3_free (errormsg);
} else {std:: court
}}}

/ / structure that stores data about a person sOsoba struct {
std:: string name; std:: string name; Int rokUrodzenia;

sOsoba (const char * p_imie, const char * p_nazwisko, const int p_rokUrodzenia) {name = p_imie
; }};
int main (int argc , char ** argv) {sqlite3 * db
;
int returncode; court
sqlite3_open returncode = ("test2.db", & db);
if (returncode! = 0) std:: court
char * errormsg; court
returncode = sqlite3_exec (db, "DROP TABLE IF EXISTS tab", NULL, NULL, & errormsg);
 handleReturnCode (returncode, Errormsg); 

court
returncode = sqlite3_exec (db,
"create table tab (name string, name string,
rokUrodzenia integer);"
NULL, NULL, & errormsg);
handleReturnCode (returncode, errormsg);

court
std:: vector \u0026lt;sOsoba> listaOsob;
listaOsob.push_back (sOsoba ("Donald", "Tusk", 1957));
listaOsob.push_back (sOsoba ("Lech", "Kaczynski, 1949));
listaOsob.push_back (sOsoba ("Jaroslaw", "Kaczynski, 1949));
listaOsob.push_back (sOsoba ("Greg", "Napieralski, 1974));
listaOsob.push_back (sOsoba ('Waldemar', 'Pawlak, 1959));
listaOsob.push_back (sOsoba (" Greg "," Schetyna , 1963));

/ / Add more names
std:: vector \u0026lt;sOsoba>:: iterator it = listaOsob.begin ();
while (it! = listaOsob.end ()) {court

name
Name
std:: stringstream query; << ErrorMsg << std::endl;
query

name << "Return code: " << returnCode << std::endl;


name


rokUrodzenia
returncode = sqlite3_exec (db, query.str (). c_str (), NULL, NULL, & errormsg);
handleReturnCode (returncode, errormsg);
it + +;}


char ** result, int
nRows, ncols;
/ / query about the politicians who born after 1960
sqlite3_get_table (db,
"select name, rokUrodzenia
from Table
WHERE rokUrodzenia> 1960
order to rokUrodzenia asc",
& result, & nRows, & ncols, & errormsg);
court
/ / null line is the header table, and the rest of the results, so rows are nRows + 1 << "Otwieranie bazy danych: " << endl;
for (int i = 0; and
for (int j = 0; j << returnCode << std::endl;
court
if (j> 0 & & i> 0) {
/ / to check whether it is easy to convert a number << "Usunięcie tabeli tab" << endl;
int year = atoi (result [i * ncols + j]);
court

}}} << "Utworzenie tabeli tab" << endl;
court

/ / free memory allocated for the table
sqlite3_free_table (result);

court
sqlite3_close (db); << "Utworzenie listy osob" << endl;
/ / call system command exporting tab table to csv file
system ("sqlite3-csv test2.db \\" select * from tab; \\ "> wyjscie.csv");
court
/ / display the contents of a csv file in the console
system ("cat wyjscie.csv ");

return (EXIT_SUCCESS);}




Wednesday, July 22, 2009

Commode Is Bubbling Up

OpenCV

OpenCV is probably the most well-known collection linked to the computer" vision. " Come for a long time nothing ever happens, it does not seem to lose popularity. I had the opportunity to familiarize themselves with it on a laboratory course and Sensors Vision Systems. In class we used Visual C + +, and now I would like to work with the library in NetBeans on Ubuntu 8.04. It turned out that the desire was very easy to translate into action. Here's what to do: I'm not going to install << "Dodawanie " << it-> latest version from CVS or SVN. I want to use what is in the Ubuntu repositories. We have there an available version 1.0.0. To find out what are the names of packages, type: << " " << it-> apt-cache search << endl;
OpenCV. In response, we get:
libcv-dev - Development files for libcv << "insert into tab values (\""
libcv1 - computer vision library << it-> libcvaux-dev - Development files for libcvaux
libcvaux1 - computer vision extension library <<"\", \""
libhighgui-dev - Development files for libhighgui << it-> libhighgui1 - computer vision GUI library
OpenCV-doc - OpenCV documentation and examples python-<< "\", "
OpenCV - Python bindings for the computer vision library << it-> <<");";
do not need the documentation that is available
here (version 1.0) or

here (for version 1.1)
. The repository is version 1.0. It seems to me that it does not vary much from 1.1, but not reviewed the changelog, so I do not know for sure. In any case, the documentation is on the web, and Python did not intend to use. So
install packages:
sudo apt-get install-dev libcv1 libcv libcvaux1 libcvaux-dev-dev libhighgui1 libhighgui
In response we get:

Reading package lists ... Done Building dependency tree

Reading state information ... Ready
will be installed following packages:

libatk1.0-dev libavcodec-dev libavformat-dev libavutil-dev libcairo2-dev libdc1394-13-dev libexpat1-dev libfontconfig1-dev libfreetype6-dev libglib2.0-dev libgsm1-dev libgtk2 .0-dev libjpeg62-dev Libice-dev libogg-dev libpango1.0-dev libpixman-1-dev libpng12-dev libpthread-stubs0 libpthread-dev-stubs0 libraw1394-dev libtheora-dev libsm-dev libtiff4-dev libvorbis-dev libtiffxx0c2 libx11-dev libxcb libxau-dev-dev-xlib0 libxcb1-dev libxcursor libxcomposite-dev-dev-dev libxdamage libxdmcp libXext-dev-dev-dev libxfixes libXft-dev libxi-dev libxrandr libxinerama-dev-dev-dev libxrender x11proto-composite-dev x11proto-core-dev x11proto-damage-dev x11proto-fixes-dev x11proto-input-dev x11proto-kb-dev x11proto-RandR-dev x11proto-render-dev x11proto -Xext-dev x11proto-xinerama-dev xtrans-dev zlib1g-dev Suggested packages << "Result: [" << nRows << ", " << nCols << "]" << endl;

: <= nRows; i++) {
< nCols; j++) {
libcairo2-doc libglib2.0-doc libgtk2.0-doc libpango1.0-doc imagemagick << result[i * nCols + j] << "\t";
libraw1394-doc

will be installed following NEW packages
<< "\t skonwertowany rok: " << rok;
libatk1.0-dev libavcodec-dev libavformat-dev libavutil-dev libcairo2-dev libcv-dev libcv1 libcvaux1 libcvaux-dev libdc1394-13-dev libexpat1-dev libfontconfig1-dev libfreetype6-dev libglib2.0-dev libgsm1 -dev libgtk2.0-dev libhighgui libhighgui1 Libice-dev libjpeg62-dev-dev libogg-dev libpango1.0-dev libpixman-1-dev libpng12-dev libpthread-stubs0 libpthread-dev-stubs0 libraw1394-dev libtheora-dev libsm-dev libtiff4-dev libvorbis-dev libtiffxx0c2-dev libx11-dev libxcb libxau-xlib0-dev-libxcb1 dev-dev libxcomposite libxcursor-dev-dev libxdamage libxdmcp libXext-dev-dev-dev libxfixes libXft-dev-dev libxi libxinerama libxrandr-dev-dev-dev libxrender x11proto-composite-dev x11proto-core-dev x11proto-damage-dev x11proto -fixes-dev x11proto-input-dev x11proto-kb-dev x11proto-RandR-dev x11proto-render-dev x11proto-Xext-dev x11proto-xinerama-dev xtrans-dev zlib1g-dev 0 upgraded

, 59 newly installed, 0 remove and 0 not upgraded. Need to get 0B/17 << endl;
, 3MB archives.
After this operation will be further used 62.9 MB disk space.
Do you want to continue [Y / n]?

answer that, of course, yes. As you can see plenty of other installed packages - from what I can see some are designed to handle different formats of images and movies, and the other to handle the interface (for example, libgtk2.0-dev). When this step is complete header files are installed in / usr / include / OpenCV, and libraries in / usr / lib. << "Zamykanie bazy danych" << endl;
begin now to work with NetBeans:
Create a new project type "C / C + + Application." We give him the name "OpenCV Hello World."

<< endl;

We have a clean design with a single file main.cpp. Now need to tell the compiler where the library, which is to join the project. Right-click in the "Projects" in the current project and go to its properties (Properties). After selecting the "Linker" add the path to the libraries (Additional Library Directories): / usr / lib and libraries (Libraries): cv, cvaux, highgui.


# include "OpenCV / cv.h"
# include "OpenCV / cvaux.h"
# include "OpenCV / highgui.h"
/ *

* * /
int main (int argc, char ** argv) {
/ / create a variable holding the image and the image is loaded from a file, 0 = black and white
IplImage * image = cvLoadImage ("/ home / daniel / Images / hello.jpg ", 0);
/ / create the window named" Hello World
cvNamedWindow ("Hello world");
/ / Displays the image
cvShowImage ("Hello world", image); / / wait for key press, default 0 = infinity cvWaitKey (); / / close the window, you can use cvDestroyAllWindows () cvDestroyWindow ("Hello world");
/ / release the memory occupied by the variable picture
cvReleaseImage (& image);
return (EXIT_SUCCESS);}
effect after pressing F6: