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.