Compiling Postgresql disable "fno-aggressive-loop-optimizations"? - c

I'm trying to compilation and install PostgreSQL in my system. My operating System is Debian 9 gcc-4.9 Below posted is my error
The database cluster will be initialized with locale en_US.UTF-8. The default database encoding has accordingly been set to UTF8.
creating directory p01/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers/max_fsm_pages ... 24MB/153600
creating configuration files ... ok
creating template1 database in p01/pgsql/data/base/1 ... ok
initializing pg_authid ... FATAL: wrong number of index expressions
STATEMENT: CREATE TRIGGER pg_sync_pg_database AFTER INSERT OR UPDATE OR DELETE ON
pg_database FOR EACH STATEMENT EXECUTE PROCEDURE flatfile_update_trigger();
child process exited with exit code 1
initdb: removing data directory "p01/pgsql/data"
In another post, a user suggests to disable the "fno-aggressive-loop-optimizations". But how can I disable this? It is a parameter in ./configure when compiling the fonts. See below the suggestion:
initdb: initializing pg_authid ... FATAL: wrong number of index expressions
I ran into the same problem after compiling postgresql 8.1.4 with gcc 4.9.3.
The problem seems to be the way postgres uses to represent variable length arrays:
typedef struct
{
int32 size; /* these fields must match ArrayType! */
int ndim;
int flags;
Oid elemtype;
int dim1;
int lbound1;
int2 values[1]; /* VARIABLE LENGTH ARRAY */
} int2vector; /* VARIABLE LENGTH STRUCT */
In some cases, for loops accessing 'values', GCC assumes that they will do one iteration at most. Loops like the one below (extracted from postgres's source code):
ii->ii_NumIndexAttrs = numKeys;
for (i = 0; i < numKeys; i++)
ii->ii_KeyAttrNumbers[i] = indexStruct->indkey.values[i];
might end up being reduced to something like:
ii->ii_NumIndexAttrs = numKeys;
if (numKeys)
ii->ii_KeyAttrNumbers[0] = indexStruct->indkey.values[0];
as deduced by looking at the assembler generated for it:
.L161:
testl %r12d, %r12d
movl %r12d, 4(%rbx)
jle .L162
movzwl 40(%r13), %eax
movw %ax, 8(%rbx)
.L162:
The problem went away after re-compiling postgres with that optimization disabled by using -fno-aggressive-loop-optimizations.

Thank you for the tips... I was able to solve the problem.
Here's the solution if someone has this problem.
To compile PostgreSQL 9.0.1 sources using GCC-4.9, I used the following directive in postgresql source:
./configure -prefix=/opt/postgres9.0 CFLAGS="-Wno-aggressive-loop-optimizations"
Wno-aggressive-looop-optiimizations disables aggressive GCCs Optimization, avoiding the error reported in previous message and in discussion-List pgsql-general ->
https://www.postgresql.org/message-id/CAOD%3DoQ-kq3Eg5SOvRYOVxDuqibVWC8R0wEivPsMGcyzZY-nfzA%40mail.gmail.com
I hope the removal of "GCCs aggressive loop optimization" does not cause any errors of any kind in the DBMS.

Related

Change active partition of LTO tape

I've been trying to change the active partition of an LTO8 tape in Windows (7 & Server 2012 R2) using the following code snippet (which gcc compiles without any warnings):
DWORD partition= 2;
if(SetTapePosition(hTape, TAPE_LOGICAL_BLOCK, partition, 0, 0, FALSE) != NO_ERROR)
<irrelevant error code here>
which returns without any errors. But it doesn't change the partition. I can use the same function and handle to seek to various blocks within the first (default) partition, so I don't think that's the problem.
The tape is definitely partitioned, and I have no problem changing to the second partition under linux using the mt command.
Turns out the issue is with Quantum's device driver; if I force load HP's device driver, I can change the active partition without any issue.

Descend/resolve user-space C function code down to kernel-space at compile time?

I may not be able to come back to this question immediately, but I thought I'd jot it down now that I've encountered it:
First of, I'm not sure what the proper way to call this is; I've tried "descend" and "resolve" in the title, but I'd like to know if there is a more proper term. In essence, what I'd like is to obtain something like shown on this image I got from Kernel System Calls - ar.linux.it:
Here is a more concrete example - consider the following small and non-working (it will simply cause an "Assertion failed"), but compilable ALSA code:
// atest.c
#include <alsa/asoundlib.h>
static snd_pcm_t *playbck_pcm_handle;
static char wrsrcbuf[256] = {[0 ... 255] = 5}; // initialization gcc specific
static snd_pcm_uframes_t period_frames = 32;
static int ret;
int main() {
ret = snd_pcm_writei(playbck_pcm_handle, wrsrcbuf, period_frames);
return 0;
}
I can build this with:
gcc -Wall -g atest.c -lasound -o atest
... and then, I can observe assembly with objdump:
$ objdump -d -M intel -S atest
...
int main() {
...
ret = snd_pcm_writei(playbck_pcm_handle, wrsrcbuf, period_frames);
804842d: 8b 15 40 a1 04 08 mov edx,DWORD PTR ds:0x804a140
...
8048447: e8 0c ff ff ff call 8048358 <snd_pcm_writei#plt>
...
return 0;
8048451: b8 00 00 00 00 mov eax,0x0
}
...
... and this tells me only that a subroutine <snd_pcm_writei#plt> will be called - but it doesn't tell me in, say, which library object file (sidenote: given compilation passed, would that mean that gcc would know about the location of the library as an object file on the current system?)
Then, I can in principle run the program (though not this one), and by using the built-in Linux tracing (ftrace) functionality in /sys/kernel/debug/tracing/trace, obtain a run-time kernel log. Due to the preemptive nature and scheduling of the kernel, one cannot really count on any constancy in order of execution, but in principle, we could get something like this (not from the above example though, as it doesn't do any proper device initialization):
sys_ioctl() {
...
do_vfs_ioctl() {
snd_pcm_playback_ioctl() {
snd_pcm_playback_ioctl1() {
_cond_resched();
copy_from_user() {
...
}
snd_pcm_lib_write() {
snd_pcm_lib_write1() {
_raw_read_lock_irq();
_raw_spin_lock();
snd_pcm_update_hw_ptr() {
snd_pcm_update_hw_ptr0() {
azx_pcm_pointer() {
...
So, this tells me that in response to the snd_pcm_writei command - ultimately sys_ioctl -> snd_pcm_playback_ioctl -> snd_pcm_lib_write will be called, which would be ALSA functions built into the kernel; however, also functions like azx_pcm_pointer() will be called, which are part of a device driver (azx_pcm_pointer is part of the hda-intel driver).
So my question is - is there an application that could output the function "descent" tree of a program from userspace to kernel space - either at compile-time (which would be gcc itself, but with some special switches if they exist for that purpose), or post-compile (like when using objdump, which is however not "runtime", as the analyzed program itself is not running)? E.g. for this example, I'd hope for an output like:
int main() { # atest
...
ret = snd_pcm_writei(playbck_pcm_handle, wrsrcbuf, period_frames); # atest
...
<snd_pcm_writei#plt> # libasound.so ??
...
sys_ioctl() { # ???.(k)o?
...
snd_pcm_playback_ioctl() { # ???.(k)o?
...
azx_pcm_pointer() { # /lib/modules/.../sound/pci/hda/snd-hda-intel.ko
...
...
I understand that the code could take a number of code paths - so hopefully this tool would be able to resolve them all - or allow for setting of variables, to limit the number of code paths; but in general, the output would be a tree (which could then be visualized with, say, graphviz).
I also understand that resolving drivers may not be possible without going into runtime (since a device - and its driver - could be specified at runtime by, say, command line arguments of the user-space program); but I'd hope at least for a notification telling me something like "Here an unspecified driver function would be called".
sidenote: given compilation passed, would that mean that gcc would know about the location of the library as an object file on the current system?
Yes, this is exactly why you have to specify -lasound. This function was found by linker. If for some reasons libasound don't have it - you'll get linking error.
So my question is - is there an application that could output the function "descent" tree of a program from userspace to kernel space
None of i've heard of. It is surely possible, but transition between user and kernel spaces are far from mere function call. In fact, userspace library using syscall() function, which sets appropriate system call number and parameters to registers and issuing special CPU interrupt, which kernel catches and then executes - so neither gcc nor any object code parsing tools can trace this transition. My best guess is dumping both user and kernel spaces and connecting this logs afterwards, but it would be tricky.
Why do you want this, by the way?

Running OpenMP on a single node of a cluster

I am able to do simple for loops in OpenMP on my desktop/laptop of the form (a mild simplification of what I actually have...)
#include <stdlib.h>
#include <stdio.h>
#include <omp.h>
%%%% #include other libraries...
int main(void){
.
.
.
%%% declare and initialize variables.
.
.
.
#pragma omp parallel for collapse(3) shared(tf, p, Fx, Fy, Fz) private(v, i,j,k,t0)
for (i = 0; i < Nx; i++){
for (j = 0; j < Ny; j++){
for (k = 0; k < Nz; k++){
v[0] = Fx[i][j][k];
v[1] = Fy[i][j][k];
v[2] = Fz[i][j][k];
///My_fn changes v and then I put it back into Fx, Fy, Fz
My_fn(v, t0, tf, p);
Fx[i][j][k] = v[0];
Fy[i][j][k] = v[1];
Fz[i][j][k] = v[2];
}
}
}
}
If I want, I can even specify to use n_threasds = 1, 2, 3 or 4 cores on my laptop by adding omp_set_num_threads(n_threads); to the top, and I notice the performance I want. However, when using a cluster, I comment that line out.
I have access to a cluster and would like to run the code on a single node since the cluster has nodes with up to 48 cores and my laptop only 4. When I use the cluster, after compiling, I type into the terminal
$export OMP_NUM_THREADS=10
$bsub -n 10 ./a.out
But the program does not run properly: I output into a file and see it took 0 seconds to run, and the the values of Fx, Fy and Fz are what they are when I initiate them, so it seems the loop is not even run at all.
Edit: This issue was addressed by the people who managed the cluster, and is likely very specific to that cluster, hence I caution people to relate the issue to their specific case.
Looks to me that this question has nothing to do with programming but rather with using the batch system (a.k.a. distributed resource manager) on your cluster. The usual practice is to write a script instead and inside the script set OMP_NUM_THREADS to the number of slots granted. Your batch system appears to be LSF (a wild guess, based on the presence of bsub), then you'd mostly like to have something similar in the script (let's call it job.sh):
#BSUB -n 10
export OMP_NUM_THREADS=$LSB_DJOB_NUMPROC
./a.out
Then submit the script with bsub < job.sh. LSF exports the number of slots granted to the job in the LSB_DJOB_NUMPROC environment variable. By doing the assignment you may submit the same job file with different parameters like: bsub -n 20 < job.sh. You might need to give a hint to the scheduler that you'd like to have all slots on the same node. One can usually do that by specifying -R "span[ptile=n]". There might be other means to do that, e.g. an esub executable that you might need to specify:
#BSUB -a openmp
Please, note that Stack Overflow is not where your administrators store the cluster documentation. You'd better ask them, not us.
I am not sure that I understand correctly what you are up to, but I fear that your idea is that OpenMP would automatically run your application in a distributed way on a cluster.
OpenMP is not made for such a task, it supposes that you run your code in a shared memory setting. For a distributed setting (processors only connected through a networking link) there are other tools, namely MPI. But such a setting is a bit more complicated to set up than just the #pragma annotations that you are used to when using openMP.
Hristo is right, but i think you should add
#BSUB -R "span[hosts=1]" # run on a single node
in your .sh file. The ptile option is only to specify the number of tasks per node
, see i.e
https://doc.zih.tu-dresden.de/hpc-wiki/bin/view/Compendium/PlatformLSF
Otherwise, depending on the queue settings of the cluster, which you might get with
bqueues -l
the task would be runned on every node, which is available to you.
If the node has 24 cores
#PBS -l nodes=1:ppn=24
in my system. Probably in the cluster you use it will be like
#BSUB -l nodes=1:ppn=24

Editing php.ini to instal Xdebug

All,
I'm a relative newbie programmer and I want to install Xdebug to help me debug my PHP work. I'm using Wamp on a Windows XP machine.
I uploaded the content of my phpinfo() onto the Xdebug site, and as part of the tailored installation instructions I get:
Edit C:\wamp\bin\apache\Apache2.2.11\bin\php.ini and add the line
zend_extension =
c:\wamp\bin\php\php5.3.0\ext\php_xdebug-2.1.2-5.3-vc6.dll
I have never opened that file before, and when I open it I find that every single setting is placed in a paragraph with some comments - for example:
[Tidy]
; The path to a default tidy configuration file to use when using tidy
; http://php.net/tidy.default-config
;tidy.default_config = /usr/local/lib/php/default.tcfg
; Should tidy clean and repair output automatically?
; WARNING: Do not use this option if you are generating non-html content
; such as dynamic images
; http://php.net/tidy.clean-output
tidy.clean_output = Off
So should I type something like that:
[Xdebug]
; This is the line to be inserted per the set-up instructions (2012-01-05)
zend_extension = c:\wamp\bin\php\php5.3.0\ext\php_xdebug-2.1.2-5.3-vc6.dll
I assume the [...] and the ; are not read by the server but I'm really not sure what they are and I don't want to screw things up...
Thanks,
JDelage
you only need the one line. Sections [..] and ; are ignored in PHP's parser. So all you need is:
zend_extension = c:\wamp\bin\php\php5.3.0\ext\php_xdebug-2.1.2-5.3-vc6.dll
cheers.
Derick

accessing sqlite with C program

Core dumped while running this program:
int main(void) {
sqlite3 *conn;
int error = 0;
error = sqlite3_open("cloud_db.sqlite3", &conn);
if (error) {
puts("Can not open database");
exit(0);
}
error = sqlite3_exec(conn,
"update server set servername=\'Laks\' where ipaddress=\'192.168.1.111\'",
0, 0, 0);
if (error) {
puts("Can not update table");
exit(0);
}
sqlite3_close(conn);
return 0;
}
I have tried accessing (select query) sqlite using C and it shows the contents - that's fine. How can I use queries like update? Above I'm trying to execute a query like:
update server set servername="Laks" where ipaddress="192.168.1.111";
running this query with in sqlite> works fine. How to execute (update query) it from C program?
Since you point out that the problem is there when the statement contains "servername=\'Laks\'" and leaves when you change that to "servername=Laks" I guess the backslashes cause the problem. You don't need backslashes to escape the apostrophe in string literals. Simply use "servername='Laks'". You escape quotes (") in string literals and apostrophes (') in character literals, but not vice versa.
You also need to add the semicolon (;) at the end of the query string: "whatever sql statement text;".
sharptooth is right on when he asks which statement leads to the core dump. Since you haven't answered, I'm thinking you may not know how to do that.
First off, make sure your program is compiled with debug symbols. Assuming you're using gcc, you do that by having -g on the command line.
Next, make sure your environment will write core files. Do this with the shell command ulimit -c unlimited (when running in sh, bash, etc.) or limit core unlimited (when running in csh).
Run the program and let it crash.
Next, bring up the core in gdb with gdb programname corename.
Finally, run the backtrace command in gdb to see where the crash was.

Resources