čtvrtek 27. dubna 2017

mixing C and Fortran code

To call the FORTRAN subroutine from C code:

      SUBROUTINE GETF(N,T,Y,F,PAR)
      IMPLICIT NONE
      INTEGER N
      DOUBLE PRECISION T, F(N), Y(N), PAR(*)
...
      RETURN
      END 

add declaration in C code:
 
void getf_(const int *N, double *t, double Y[], double F[], double PAR[]);

(keep in mind, that all parameters in FORTRAN are passed by reference)

The C call statement is then

int main (int nargin, char **args)
{
 const int N=6;
 double t, y[N], f[N], p[2];
 p[0]=3.14;p[1] =2.71828;
 t=0.1;
 for (i=0;i<N;i++) y[i]=0.0; 
 
 getf_(&N, &t, y, f, p); 
 
 for (i=0;i<N;i++) printf(" %.5e", y[i]);
 return ;
}

Compilation:
gforftan -c funcf.f
gcc main.c funcf.o -o a.out

čtvrtek 5. ledna 2017

COMSOL in VNC environment (linux server)

According to this thread, COMSOL is not compatible with remote access. When started in the VNC window, it complaints against "Could not initialize 3D graphics" and "Could  not initialize 3D renderer". The problem could be caused by installed nvidia proprietary graphics libraries  (used for CUDA computation).

Solution is to set the  environment variable USEMESA=1 and start comsol with the command:

server:~> USEMESA=1 comsol 

Alternatively, the value 1 can be specified directly in the comsol startup script.
Tested on v4.3a, v4.4, v5.1.

úterý 9. srpna 2016

batch doc/docx to odt (and epub) convertion

Thanks to CRC OK.


libreoffice --headless --convert-to odt ./*doc

I have seen and used this solution already in the past, due some strange restriction it was necessary to run the command as root. Currently such a restriction does not apply. Tested on CentOS Linux release 7.2.1511, libreoffice-writer-4.3.7.2-5.el7_2.1.x86_64.


PS. conversion to epub is as usual:

ebook-convert file.odt file.epub \
--authors "Scheer, Karl Herbert" \
--title "Perry Rhodan: Odlet MARCA POLA" \
--series "Perry Rhodan" \
--series-index 450

čtvrtek 5. května 2016

unrecognised SATA drives / Marvell 88SE6145

Motherboard "NAS 7800" has 8 sata ports, 4 are connected to VIA sata controller, the other 4 are those of Marvell 88SE6145. Whereas the VIA ports work well with OpenSuse 13.2 with pata_via module, the Marvell ports do not recognise attached drives:

ata8: SRST failed (errno=-16)
ata8: link is slow to respond, please be patient (ready=0)

or
ata4: exception Emask 0x10 SAct 0x0 SErr 0xb0000 action 0xe frozen
ata4: irq_stat 0x04400000, PHY RDY change
ata4: SError: { PHYRdyChg PHYInt 10B8B }
ata4: hard resetting link
ata4: SATA link down (SStatus 0 SControl 300)
ata4: hard resetting link
...
According to Allan Cox's solution the automatically identified module should be substituted by the
ahci module with option marvell_enable=1. To do so:
create options file for ahci module:
echo "options ahci marvell_enable=1" >/etc/modprobe.d/my-marvel.conf 

blacklist the broken(?) pata_marvell (append to blacklist file):
echo "blacklist pata_marvell" >>/etc/modprobe.d/50-blacklist.conf

delete pata_marvell from initrd modules in /etc/sysconfig/kernel:
INITRD_MODULES="ahci pata_via ata_generic"

and re-create initrd
mkinitrd

reboot

Remark to the Marvell 88SE6145 raid 0/1/5 controller: it is a sw raid controller, drives appear in linux as JBOD regardless of BIOS settings.

úterý 5. dubna 2016

CentOS: change the system drive

Let's have a standard installation of a recent CentOS (6.5, Jan 2014).

The disk layout (created by the installation script) is

[root@server]# fdisk /dev/sdb
Disk /dev/sdb: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00009e69

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2              64       14594   116707328   8e  Linux LVM

[root@server]#  mount |grep ^/dev
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
/dev/sdb1 on /boot type ext4 (rw)
/dev/mapper/VolGroup-lv_home on /home type ext4 (rw)

However, firstly I have to replace the system disk, and secondly, I do not like LVM .

1. Initialize the new disc (/dev/sdc) : clone the boot sector (MBR) and /boot partition (it contains some EFI stuff and grub etc...)
dd if/dev/sdb of=/dev/sdc bs=512000 count=520

2. fdisk /dev/sdc
delete partiton 2 and create properly aligned swap, root and home partitions, format as ext4 (or other) fs

3. mount /dev/sdc3 /mnt/3 && mount /dev/sdc4 /mnt/4 && mount /dev/sdc1 /mnt/3/boot
rsync -avPx / /mnt/3 && rsync -avPx /home /mnt/4

4. get uuid of new partitions
blkid /dev/sdc?
and replace corresponding partitions in fstab on the new disk
vim /mnt/3/etc/fstab
UUID="414....."    /      ext4 defaults 1 1
UUID="123-..."    /boot   ext4 defaults 1 2
UUID="456-..."    swap   swap  defaults 0 0
UUID="789-..."    /home   ext4 defaults 1 2
..
4. change root partition (use UUID of the new root partition) in grub.conf and clean up the kernel command line:
vim /mnt/3/boot/grub/grub.conf

original line:
        kernel /vmlinuz-2.6.32-431.5.1.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root nomodeset rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet

new line:
        kernel /vmlinuz-2.6.32-431.5.1.el6.x86_64 ro root=UUID="759c2224-3881-4cca-a14b-f0baf771084f" nomodeset  LANG=en_US.UTF-8 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us
(no "redhat graphical boot" (rhgb), no DM raid, no MD raid, no LUKS encryption)

5. VERY IMPORTANT

touch /mnt/3/.autorelabel
(flag .autorelabel in root of the new fs forces SELINUX to relabel the filesystem.)
Otherwise login attempts on the new system  would fail with "selinux is preventing /bin/login ..."
 
 
 

pátek 4. března 2016

page allocation failure. order:3, mode:0x20

see https://access.redhat.com/solutions/90883

check
 sysctl vm.min_free_kbytes
 sysctl vm.zone_reclaim_mode

 gvim /etc/sysctl.conf
add:
 vm.min_free_kbytes = 131072
 vm.zone_reclaim_mode = 1

then
[root@titanic 2]# sysctl -p /etc/sysctl.conf
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
vm.min_free_kbytes = 131072
vm.zone_reclaim_mode = 1

--------------------------------
The problems seems to have something witn VirtualBox: different programs complain about page allocation failure, but  notice of VBoxNetFlt:is common to all errors.
cause and symptoms:
tail /var/log/messages
Feb 26 12:21:23 titanic kernel: firefox: page allocation failure. order:3, mode:0x20
Feb 26 12:21:23 titanic kernel: Pid: 3090, comm: firefox Not tainted 2.6.32-573.18.1.el6.x86_64 #1
Feb 26 12:21:23 titanic kernel: Call Trace:
Feb 26 12:21:23 titanic kernel: <IRQ>  [<ffffffff811376ac>] ? __alloc_pages_nodemask+0x7dc/0x950
Feb 26 12:21:23 titanic kernel: [<ffffffff81014a19>] ? read_tsc+0x9/0x10
Feb 26 12:21:23 titanic kernel: [<ffffffff811771c2>] ? kmem_getpages+0x62/0x170
Feb 26 12:21:23 titanic kernel: [<ffffffff81177dda>] ? fallback_alloc+0x1ba/0x270
Feb 26 12:21:23 titanic kernel: [<ffffffff8117782f>] ? cache_grow+0x2cf/0x320
Feb 26 12:21:23 titanic kernel: [<ffffffff81177b59>] ? ____cache_alloc_node+0x99/0x160
Feb 26 12:21:23 titanic kernel: [<ffffffff81178dd0>] ? kmem_cache_alloc_node_trace+0x90/0x200
Feb 26 12:21:23 titanic kernel: [<ffffffff81178fed>] ? __kmalloc_node+0x4d/0x60
Feb 26 12:21:23 titanic kernel: [<ffffffff8145eaea>] ? __alloc_skb+0x7a/0x180
Feb 26 12:21:23 titanic kernel: [<ffffffff8145faf0>] ? skb_copy+0x40/0xb0
Feb 26 12:21:23 titanic kernel: [<ffffffffa03c5b75>] ? vboxNetFltLinuxPacketHandler+0xb5/0x600 [vboxnetflt]
Feb 26 12:21:23 titanic kernel: [<ffffffff81014a19>] ? read_tsc+0x9/0x10
Feb 26 12:21:23 titanic kernel: [<ffffffff810ac488>] ? getnstimeofday+0x58/0xf0
Feb 26 12:21:23 titanic kernel: [<ffffffff8146b479>] ? __netif_receive_skb+0x4b9/0x570
Feb 26 12:21:23 titanic kernel: [<ffffffff8146eaa8>] ? netif_receive_skb+0x58/0x60
Feb 26 12:21:23 titanic kernel: [<ffffffff8146ec98>] ? napi_gro_complete+0xc8/0x150
Feb 26 12:21:23 titanic kernel: [<ffffffff8146f20f>] ? napi_gro_flush+0x2f/0x50
Feb 26 12:21:23 titanic kernel: [<ffffffff8146f254>] ? napi_complete+0x24/0x60
Feb 26 12:21:23 titanic kernel: [<ffffffffa02477d2>] ? e1000e_poll+0x122/0x280 [e1000e]
Feb 26 12:21:23 titanic kernel: [<ffffffff81470b33>] ? net_rx_action+0x103/0x2f0
Feb 26 12:21:23 titanic kernel: [<ffffffff8107ffa1>] ? __do_softirq+0xc1/0x1e0
Feb 26 12:21:23 titanic kernel: [<ffffffff810ed920>] ? handle_IRQ_event+0x60/0x170
Feb 26 12:21:23 titanic kernel: [<ffffffff8107ffff>] ? __do_softirq+0x11f/0x1e0
Feb 26 12:21:23 titanic kernel: [<ffffffff8100c38c>] ? call_softirq+0x1c/0x30
Feb 26 12:21:23 titanic kernel: [<ffffffff8100fbd5>] ? do_softirq+0x65/0xa0
Feb 26 12:21:23 titanic kernel: [<ffffffff8107fe55>] ? irq_exit+0x85/0x90
Feb 26 12:21:23 titanic kernel: [<ffffffff81543015>] ? do_IRQ+0x75/0xf0
Feb 26 12:21:23 titanic kernel: [<ffffffff8100ba53>] ? ret_from_intr+0x0/0x11
Feb 26 12:21:23 titanic kernel: <EOI> VBoxNetFlt: Failed to allocate packet buffer, dropping the packet.

čtvrtek 25. února 2016

X11: change display resolution with xrandr


1. get current state:

cyril@workstation: xrandr 
Screen 0: minimum 320 x 200, current 3840 x 2160, maximum 16384 x 16384
DFP1 connected primary 1776x1000+0+0 (normal left inverted right x axis y axis) 621mm x 341mm
   3840x2160     29.97 +  24.00    25.00    23.98    29.97  
   2560x1440     59.95  
   2048x1536     24.00    25.00    23.98    29.97    29.97  
   1920x1440     60.00  
   ...
   640x480       72.81    75.00    66.61    59.94  
DFP2 disconnected (normal left inverted right x axis y axis)
DFP3 disconnected (normal left inverted right x axis y axis)

2. change resolution:
cyril@workstation:> xrandr --output DFP1 --mode 3840x2160 --dpi 162
cyril@workstation:> xrandr --output DFP1 --mode 2560x1440
cyril@workstation:> xrandr --output DFP1 --mode 2048x1536 
 
3. in case of "unkonwn mode":

# compute parameters of new mode
cvt 1440 900 60
#then define and add new mode
xrandr --newmode  "1440x900_60.00"  106.50  1440 1528 1672 1904  900 903 909 934 -hsync +vsync 
xrandr --addmode VNC-0 1440x900_60.00
 
#and finally set 
xrandr -s 1440x900