C++Guns – RoboBlog blogging the bot

24.01.2016

Warum (kurze) Arrays in Fortran (und C/C++) nicht immer die richtige Wahl ist

Filed under: Allgemein — Tags: — Thomas @ 22:01

Der Name ist Programm.
Heute mal tex und pdf Version.

wkfanidrwi.pdf

\documentclass[]{article}
\usepackage{listings}
\usepackage[utf8]{inputenc}
\usepackage{ngerman}

%opening
\title{Warum (kurze) Arrays in Fortran (und C/C++) nicht immer die richtige Wahl ist}
\author{Thomas Huxhorn}


\begin{document}

\maketitle

\tableofcontents

\begin{abstract}
In diesem kleinen Artikel lege ich ein paar Gedanken nieder über einen Fehler mit 
(kurzen) Arrays, der systematisch immer wieder Auftritt. Die Wahl der Programmiersprache
ist unabhängig für diese Art von Fehler.
\end{abstract}

\section{Ein Fehler}
Der Fehler selbst lässt sich in einem Satz beschreiben: Einer Funktion wurde nur ein Wert
übergeben, obwohl sie ein Array von zwei Werten erwartet. Das klingt erstmal recht banal, hat es aber in sich.
Hier der entsprechende Beispiel Code in Fortran:

\begin{lstlisting}[frame=single]
subroutine func(data)
  integer, intent(in) :: data(2)
  write(*,*) data(1), data(2)
end subroutine

program test
  integer :: data(2)
  data(1) = 1
  data(2) = 2
  call func(data(1))
end program
\end{lstlisting}

Das Programm compiliert ohne Warnings, ohne Laufzeitfehlermeldungen und keinerlei Überprüfungen die 
der Compiler bereit stellt schlagen Alarm. Sogar die Ausgabe des Programms ist richtig. 
Benutzt wurde der neuste GNU Fortran Compiler in der Version 5.2.1

\begin{lstlisting}[frame=single]
$ gfortran -Wall -Wextra -fcheck=all 
-fsanitize=address,undefined wkfanidrwi1.f95
$ ./a.out 
1           2
\end{lstlisting}

\section{Ein unsichtbarer Fehler}
Auch der memory error detector valgrind findet keinerlei Fehler. Der Grund ist ganz einfach: Aus technischer
Sicht existiert in diesem Programm auch kein Fehler! Das ist auf den ersten Blick etwas verwirrend. 
Der Programmierer wollte, dass die Subroutine func() nur die erste Zahl im Array data verarbeitet. Die Subroutine 
hingegen, erwartet nicht nur zwei Zahlen, sie nimmt sich auch zwei Zahlen! Selbst, wenn man ihr nur eine gibt.
Wir haben hier also gleichzeitig zwei Arten von Fehler. Der Programmierer hat eine Vorstellung, was passieren soll.
Seine Kenntnis über die Subroutine func ist aber falsch, so dass er zu wenig Daten übergibt. Das ist der erste Fehler.
Der zweite Fehler ist, dass der Programmierer die Subroutine so erstellt hat, dass sie immer genau so viele Daten
verarbeitet, wie sie braucht. Egal ob sie auch genügend Daten bekommt. Die beiden Fehler heben sich gegenseitig auf,
und es kommt auch das richtige Ergebnis raus. Kein Programm kann den Fehler finden.

\section{Ein versteckter Fehler}
Heutzutage sind Programme riesig. Sie bestehen aus einer Millionen Zeilen Code, sind über Jahrzehnte gewachsen und kein
Mensch blickt mehr in allen Details durch. Diese Art Fehler zu erkennen ist also menschlich nicht möglich. Ein 
Computer Programm könnte es aber. Der Compiler sieht beim Compilieren das gesamte Programm, den kompletten Quellcode.
Man muss den Compiler aber auch seine Arbeit tun lassen, und nicht selbst die Arraygröße bestimmen.

\section{Lösungversuch}
Die erste Idee ist also, das die Subroutine nicht ein Array fester Größe, sondern eins variabler Größe erwartet. So kann zur
Laufzeit erkannt werden, ob zu viele oder zu wenige Daten übergeben wurden. Hier eine Beispiel Implementierung.

\begin{lstlisting}[frame=single]
module testmodule
contains
subroutine func(data)
integer, intent(in) :: data(:)
write(*,*) data(1), data(2)
end subroutine
end module

program test
use testmodule
integer :: data(2)
data(1) = 1
data(2) = 2
call func(data(1))
! call func(data(1:1))
end program
\end{lstlisting}

Sie Subroutine muss dazu in ein Modul gepackt werden, sonst können keine assumed-shape Arrays benutzt werden.

\begin{lstlisting}[frame=single]
$ gfortran -Wall -Wextra -fcheck=all wkfanidrwi1.f95
wkfanidrwi2.f95:14:12:

call func(data(1))
1
Error: Rank mismatch in argument 'data' at (1) 
(rank-1 and scalar)
\end{lstlisting}

Schon allein das Compilieren führt hier zu einem Fehler. Aber nur, weil ein Array erwartet, aber ein Skalar übergeben wurde. Das kann man ganz leicht aus tricksen, in dem man ein Array der Länge 1 übergibt. Dieser Fall wird dann, wie
erwartet, zur Laufzeit abgefangen.

\begin{lstlisting}[frame=single]
$ ./a.out 
At line 5 of file wkfanidrwi2.f95
Fortran runtime error: Index '2' of dimension 1 of array
'data' above upper bound of 1
\end{lstlisting}

Der Fehler wird jetzt zur Laufzeit erkannt. Das ist schon einmal ein riesiger Fortschritt, als wenn der Fehler nie erkannt wird. Allerdings muss nun bei jedem Array Zugriff die Länge des Arrays überprüft werden. Im Durchschnitt verdoppelt das die Laufzeit des Programms. Und der Fehler wird auch nur gemeldet, wenn entsprechende Checks im
Compiler eingeschaltet wurden. \\
Können wir das nicht besser machen? Immerhin WISSEN wir ja, wie viele Daten die Subroutine brauch. Das muss sich
ausnutzen lassen.

\section{Lösung allgemein}
Die allgemeine Lösung für diese Art von Fehler besteht darin, einfach keine Arrays für so wenige Daten zu nutzen.
Um dennoch nicht jede einzelne Zahl als Parameter zu übergeben, und damit den Code unnötig groß zu machen,
werden die Daten in einem neuen Datentyp gruppiert. \\
Da der Datentyp zwangsläufig einen Namen braucht, können wir den Variablen gleichzeitig eine Bedeutung geben. So ist
ein weiterer Fehler ausgeschlossen, dass man z.B. aus versehen data(1) statt data(2) benutzt.
Hier die Beispiel Implementierung:

\begin{lstlisting}[frame=single]
module testmodule
type Uhrzeit_t
integer :: minute, stunde
end type
contains
subroutine func(uhrzeit)
type(Uhrzeit_t), intent(in) :: uhrzeit
write(*,*) uhrzeit%stunde, uhrzeit%minute
end subroutine
end module

program test
use testmodule
type(Uhrzeit_t) :: uhrzeit
uhrzeit%minute = 1
uhrzeit%stunde = 2
call func(uhrzeit)
end program
\end{lstlisting}

Der ursprüngliche Fehler ist nun nicht mehr möglich. Unnötig Laufzeiteinverschlechterungen sind auch nicht mehr vorhanden. Der Compiler kann durch Typenüberprüfungen zur Compilezeit feststellen, ob die Subroutine immer den
richtigen Datentype erhält. \\

\section{Ausblick}
So weit so gut. Mit der Implementierung dem Uhrzeit Modul haben wir aber viele weitere Fehlerquellen erschaffen.
In der Praxis reicht es nicht einfach nur Stunde und Minute auszugeben. Datum und Uhrzeit müssen verglichen, umgerechnet, verrechnet und erstellt werden. Für all das existieren schon fertige Module, teilweise standardisierte und alle getestet. 


\section{Lösung Qt}

Qt bietet hierfür die Klasse QTime an.
Hier ein Beispiel wie ein Zeitobjekt erstellt, einer Funktion
übergeben und ausgegeben wird.

\begin{lstlisting}[frame=single]
void func(QTime time) {
	qDebug() << time.toString();
}

QTime time(1,2);
func(time);
\end{lstlisting}

QTime selbst ist eine Klasse welche nicht nur Stunden, Minuten, Sekunden
und Millisekunden speichern kann. Sondern auch die Textausgabe im
jeweiligen Landesformat übernimmt und mit der Klasse QDateTime werden
auch Winter und Sommerzeit beachtet.

\section{Technische Details des Fehlers}
Wie am Anfang erwähnt ist diese Fehlerart unabhängig der gewählten
Programmiersprache. Auch in C können Arrays als Funktions Parameter
eine feste Länge zugewiesen werden. Und da C++ rückwärts kompatibel
zu C ist, ist der Fehler auch in C++ machbar. Es hängt nicht von der 
Sprache ab, sondern die Art wie man programmiert. \\
In der Subroutine wurde ein Array fester Länge angegeben. Damit 
existiert das Array für den Compiler! und er würde so nie einen
Fehler finden. Warum die ganzen Memory Check Programm auch keinen
Fehler finden, ist recht einfach. Es existiert im Programm ja auch
ein Array richtiger Länge. Es wurde nur ein statt zwei Elemente 
übergeben. Aber in dem Moment wo in der Subroutine auf das
zweite Element zugegriffen wird, wird gültiger Speicher ausgelesen.

\end{document}


21.01.2016

template loop mit rekursion

Filed under: Allgemein — Thomas @ 09:01

Einfache Schleifen mit Templates funktionieren mittels Rekursionen. Das ist auf
dem ersten Blick etwas ungewöhnlich, aber letzendlich doch nur eine Schleife.
Wir muessen die Anzahl an Iterationen aber zur Compilezeit vorgeben! Entweder
per Template Parameter oder constexpr.

Normal würde man Parameterlisten packen/unpacken oder was man sonst in einer Schleife macht.
Ich möchte aber N mal eine Funktion mit einem laufenden Template Parameter i erstellen.
Erstens kann ich so meine Funktion für ein festes N specialisieren, zweitens kann man
die spezielle Funktion zur Laufzeit auswählen.


#include <iostream>
#include <array>

template<int N>
void funcToImpl(int n) {
  std::cout << "template N: " << N << " runtime n: " << n < fixedLengthArray;
}

template<int i>
void func(int n) {
  if(i == n) {
    funcToImpl(n);
  } else {
    func<i-1>(n);
  }
}

// rekursionsanker bei i=0
template<>
void func<0>(int n) {
  funcToImpl<0>(n);
}

int main(int argc) {
  // rekursion faengt bei i=80 an
  func<80>(argc);
}

14.01.2016

std::normal_distribution

Filed under: Allgemein — Tags: — Thomas @ 16:01

Wie baut man aus gleichverteilen Zufallszahlen normalverteile?
Man nimmt std::normal_distribution

http://en.cppreference.com/w/cpp/numeric/random/normal_distribution

Und wie ist das Implementiert? Eine Beispielimplementation gibt es in der gnu stdc++

https://gcc.gnu.org/onlinedocs/gcc-4.7.4/libstdc++/api/a01267_source.html#l01678

Wtf? Versteht kein Mesch. Das Paper auf dass die sich beziehen ist auch ein Hammer.

http://www.eirene.de/Devroye.pdf Seite 249

Hier die Template bereinigte Version vom GNU


#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <random>
#include <cmath>

double round(double x) {
    return int(x*10)/10.0;
}

// erzeugt gleichverteilte zufallzahlen im interfall [0:1]
struct uniform_real_random_device {
    std::mt19937 gen;
    std::uniform_real_distribution<> uniform_dist = std::uniform_real_distribution<>(0.0, 1.0);

    double operator() () {
        return uniform_dist(gen);
    }
};

/**
  * Polar method due to Marsaglia.
  *
  * Devroye, L. Non-Uniform Random Variates Generation. Springer-Verlag,
  * New York, 1986, Ch. V, Sect. 4.4.
  *
  * https://gcc.gnu.org/onlinedocs/gcc-4.7.4/libstdc++/api/a01267_source.html#l01678
  */
double normal_dist(uniform_real_random_device& rand, double mean, double stddev) {
    double x, y, r2;
    do
    {
        x = 2.0 * rand() - 1.0;
        y = 2.0 * rand() - 1.0;
        r2 = x * x + y * y;
    }
    while (r2 > 1.0 || r2 == 0.0);

    double mult = std::sqrt(-2 * std::log(r2) / r2);
    double result = y * mult;
    result = result*stddev + mean;
    return result;
}

int main() {
    uniform_real_random_device uniformRand;

    std::map hist;
    for(int n=0; n<100000; ++n) {
        double gaussZahle = normal_dist(uniformRand, 0.5, 0.5);
        ++hist[round(gaussZahle)];
    }

    // ausgabe
    for(auto p : hist) {
        std::cout << std::fixed << std::setprecision(1) << std::setw(2)
                  << p.first << ' ' << std::string(p.second/100, '*') << '\n';
    }
}

-1.5
-1.4
-1.3
-1.2
-1.1
-1.0
-0.9 *
-0.8 *
-0.7 ***
-0.6 *****
-0.5 ********
-0.4 ************
-0.3 ******************
-0.2 **************************
-0.1 **********************************
0.0 ************************************************************************************************
0.1 **************************************************************
0.2 *********************************************************************
0.3 ****************************************************************************
0.4 *******************************************************************************
0.5 *******************************************************************************
0.6 ****************************************************************************
0.7 **********************************************************************
0.8 *************************************************************
0.9 *****************************************************
1.0 *******************************************
1.1 **********************************
1.2 **************************
1.3 ******************
1.4 *************
1.5 *********
1.6 *****
1.7 ***
1.8 **
1.9 *
2.0
2.1
2.2
2.3
2.4
2.5

Jaaa da ist noch ein Bug drin bei der 0. Wer ihn findet, darf mir eine Mail schreiben.

03.01.2016

XKCD 1188 BOUNDING

Filed under: Allgemein — Tags: — Thomas @ 22:01

http://xkcd.com/1188/

Lame Segfault.


#include <exception>
using namespace std;
struct Ball : public exception {
};

struct P {
  P* target;
  void aim(const Ball& ball) {
    try {
      throw ball;
    }
    catch(Ball& ball) {
      target->aim(ball);
    }    
  }
};

int main() {
  P parent;
  P child{&parent};
  parent.target = &child;
  parent.aim(Ball());
}

01.01.2016

rvalues, lvalues, xvalues, glvalues, prvalues WTF??

Filed under: Allgemein — Tags: — Thomas @ 20:01

Sehr zu empfehlen:
http://www.stroustrup.com/terminology.pdf


int   prvalue();
int&  lvalue();
int&& xvalue();

void foo(int&& t) {
  // t is initialized with an rvalue expression
  // but is actually an lvalue expression itself
}

GNhBF

— An lvalue (so called, historically, because lvalues could appear on the left-hand side of an assignment expression) designates a function or an object. [ Example: If E is an expression of pointer type, then *E is an lvalue expression referring to the object or function to which E points. As another example, the result of calling a function whose return type is an lvalue reference is an lvalue. —end example ]

— An xvalue (an “eXpiring” value) also refers to an object, usually near the end of its lifetime (so that its resources may be moved, for example). An xvalue is the result of certain kinds of expressions involving rvalue references (8.3.2). [ Example: The result of calling a function whose return type is an rvalue reference is an xvalue. —end example ]

— A glvalue (“generalized” lvalue) is an lvalue or an xvalue.

— An rvalue (so called, historically, because rvalues could appear on the right-hand side of an assignment expressions) is an xvalue, a temporary object (12.2) or subobject thereof, or a value that is not associated with an object.

— A prvalue (“pure” rvalue) is an rvalue that is not an xvalue. [ Example: The result of calling a function whose return type is not a reference is a prvalue. The value of a literal such as 12, 7.3e5, or true is also a prvalue. —end example ]

Every expression belongs to exactly one of the fundamental classifications in this taxonomy: lvalue, xvalue, or prvalue. This property of an expression is called its value category. [ Note: The discussion of each built-in operator in Clause 5 indicates the category of the value it yields and the value categories of the operands it expects. For example, the built-in assignment operators expect that the left operand is an lvalue and that the right operand is a prvalue and yield an lvalue as the result. User-defined operators are functions, and the categories of values they expect and yield are determined by their parameter and return types. —end note

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3055.pdf
http://stackoverflow.com/questions/3601602/what-are-rvalues-lvalues-xvalues-glvalues-and-prvalues

14.11.2015

ZipLib ist absoluter Schrott

Filed under: Allgemein — Tags: — Thomas @ 11:11

ZipLib von mindless-area ist absoluter Schrott. Vom c++11 Spirit seh ich nichts im Code aber das schlimmste ist die Laufzeit. Ein einfaches unzippen von zwei 30MB Datei mit ZipFile::Open() dauerte 3 Minuten. Das gunzip Programm schaff es in 5 Sekunden. 180sec vs. 5sec. Was macht der Typ da? Vor allem hat er den eigentlichen ZIP Algorithmus nicht mal implementiert. Er leitet es nur an die alten Libraries weiter. Finger weg!

13.11.2015

std::string trimmed std::string_view

Filed under: Allgemein — Tags: — Thomas @ 13:11

There is no trim() trimmed() member function in std::string. A free function is better.

Here is one nice solution which has a linear running time and not quadratic like using erase(). (Stupid programmer out there)
From:
http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring

std::string trimmed(const std::string &s) {
   auto wsfront=std::find_if_not(s.begin(),s.end(), [](int c){return std::isspace(c);});
   auto wsback=std::find_if_not(s.rbegin(),s.rend(),[](int c){return std::isspace(c);}).base();
   return (wsback<=wsfront ? std::string() : std::string(wsfront,wsback));
}
std::string_view trimmed(std::string_view s) {
    auto wsfront = std::find_if_not(s.begin(),s.end(), [](int c){return std::isspace(c);});
    // base() returns the forward iterator from reverse iterator returned by rbegin()
    auto wsback = std::find_if_not(s.rbegin(),s.rend(),[](int c){return std::isspace(c);}).base();
    return wsback <= wsfront ? std::string_view() : std::string_view(wsfront, wsback-wsfront); //  its a lower than there. F wordpress
}

27.10.2015

Enum Array replacement - some kind of

Filed under: Allgemein — Tags: — Thomas @ 18:10

Type safe enum class replace with normal class.
Used as an index (key) type for continuous containers like std::vector / std::array instead of std::map etc.

Pro: Fun.
Con: dynamic indice. myEnumIdx.somedata = 100000; can blow up the hole thing.

For static enum array see
http://fcppt.org/da/dcf/classfcppt_1_1container_1_1enum__array.html#af01f0518d2f63f4fd47eb5c510855c63
http://fcppt.org/d6/ddd/group__fcpptenum.html


#include <vector>

template<typename Key, typename Value>
class EnumArray {
public:
    
    Value & operator[](const Key& key) {
        return data[key];
    }
    
private:
    std::vector<Value> data;
};

class EnumType {
public:
    int someData = 0;
    
private:
    operator int() const {
        return someData;
    }
    
    template<typename EnumType, typename>
    friend class EnumArray;
};

class EnumType2 {
public:
    int someData = 0;
    
private:
    operator int() const {
        return someData;
    }
    
    template<typename EnumType2, typename>
    friend class EnumArray;
};

void testfunc() {
    EnumType myEnumIdx;
    
    // does not compile
    std::vector<int> vec1(10);    
    // error: ‘EnumType::operator int()’ is private
    // vec1[myEnumIdx] = 1; 
    
    // does compile cause EnumArray is a friend of EnumType and can array private implicit conversion operator to int
    EnumArray<EnumType, int> arr;
    arr[myEnumIdx] = 1;
    
    EnumType2 myEnumIdx2;
    // does not compile
    // error: no match for ‘operator[]’ (operand types are ‘EnumArray’ and ‘EnumType2’)
    // note:   no known conversion for argument 1 from ‘EnumType2’ to ‘const EnumType&’
    arr[myEnumIdx2] = 1;    
}


06.10.2015

Infiniband Cluster

Filed under: Allgemein — Thomas @ 20:10

IBcluster5

IBcluster2

IBcluster

staubfilter1

LD_LIBRARY_PATH=/home/kater/bin/ las2txt64 -parse xyz -odir . -i 47605560_all_thin.las -keep_class 2

GIT

Repair Permissions
The repository isn't configured to be a shared repository (see core.sharedRepository in git help config). If the output of:
git config core.sharedRepository
is not group or true or 1 or some mask, try running:
git config core.sharedRepository group

cd /path/to/repo.git
chgrp -R groupname .
chmod -R g+rwX .
find . -type d -exec chmod g+s '{}' +

GIT Branch dauerhaft anzeigen. in .bash_rc

parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* /(\1)/'
}
export PS1="\u@\h

\w

\$(parse_git_branch)

$ "

samba SMB

To enable old Version 1 SMB protocol version add vers=1.0
Die user Option hat eine doppelte Bedeutung. Steht sie allein, werden keine root Rechte zum mounten benötigt. Wird ein username bei user= angegeben, so bezieht sich dieser auf den Server. Die Option users mit einem s am Ende erlaubt, dass keine root Rechte benötigt werden und dass alle user die Partition umounten kann.
uid=
gid=

Für Multiusersysteme ist die Option noperm für cifs mounts hilfreich.
Schreibrechte checken!

192.168.10.49:/perm     /perm           nfs     noauto,nosuid,hard,user         0       0
192.168.10.49:/karten   /karten         nfs     noauto,nosuid,hard,user         0       0

//192.168.10.13/data             /laufwerkG      cifs    noauto,hard,users,user=standard,password=standard,vers=1.0,uid=1000,gid=998,noperm,exec       0       0


IGM samba SMB

Neuen User mit adduser anlegen. Default group auf users ändern
# sudo usermod -g users mhu
In Webmin neuen User convertieren
In Webmin Service restart
Point 139 445 forwarden
In Konquerror smb://mhu@localhost/
oder in der Konsole sudo mount -t cifs -o user=mhu //localhost/IGM-2 mnt/
testen

RAID

Allgemeiner Status:
$ cat /proc/mdstat
Die Angaben in dne [] Klammern sind Informationen pro Platte. Z.B. [UU] für 2 Platten.
U - Up
S - spare (schonen)
_ - Down

Informationen zum einzelnen Raid
$ mdadm -D /dev/md0

Hm immer gut
$mdadm --assemble --scan -v

Jede Partition einzeln untersuchen
$ mdadm -E /dev/sda1
$ mdadm -E /dev/sdb1

RAID Einrichten:
https://www.thomas-krenn.com/de/wiki/Linux_Software_RAID

Partition auf jede Festplatte erstellen mit Type Linux Raid
RAID mit mdadm erstellen
mdadm --create /dev/md0 --level=0 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1

Dateisystem erstellen
mkfs.ext4 /dev/md0

UUID einer Festplatte herausfinden
root@login02:~# blkid /dev/sda
/dev/sda: UUID="7578c0b0-8fbe-44ba-93f4-cd55fe64e220" BLOCK_SIZE="4096" TYPE="ext4"

BACKUP and EMAIL notify

Backup Script:
rsync --numeric-ids --stats -hPave ssh /IGM2 192.168.://share/CACHEDEV1_DATA/data > `date "+%y%m%d"_copyprotocol`
echo -e "Subject: Backup PS2NAS\n\n" > tmp; cat `date "+%y%m%d"_copyprotocol` >> tmp; cat tmp | msmtp mail@me

Bei Fehler:
msmtp: TLS certificate verification failed: the certificate fingerprint does not match
msmtp: could not send mail (account default from /root/.msmtprc)

Das tun:
msmtp --serverinfo --tls --tls-certcheck=off --host=smtp.1und1.de --port 587

Und du bekommst:
SHA256: 6F:5C:80:76:FB:8A:82:02:E9:23:AB:4A:68:F4:E2:6C:B6:29:72:70:82:5D:02:F8:F5:A5:AB:AC:67:D3:72:61

Logical Volume Management

$ vgdisplay
Alloc PE / Size 29440 / 115.00 GiB
Free PE / Size 207491 / 810.51 GiB

$ lvextend -L910.51G /dev/mapper/vg00-home
Rounding size to boundary between physical extents: 910.51 GiB
Size of logical volume vg00/home changed from 100.00 GiB (25600 extents) to 910.51 GiB (233091 extents).
Logical volume home successfully resized.

$ resize2fs /dev/mapper/vg00-home
Filesystem at /dev/mapper/vg00-home is mounted on /home; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 57
The filesystem on /dev/mapper/vg00-home is now 238685184 (4k) blocks long.

$ df -h
/dev/mapper/vg00-home 897G 560M 860G 1% /home

Software

Put
apt::install-recommends "false";
in /etc/apt/apt.conf after installed basesystem to get rid of stupid nonsense software on a server.
Check with "aptitude why " and apt-config dump |fgrep -i recommend


Don't install these

kde-runtime

Don't deinstall

# IB
libmlx4-1 libmthca1

# obviously
meld

# for deptherror script
python-matplotlib
python-numpy
python-tk

Check for

*kde*
*gnome*
*gtk*
*vlc*
*wx*
libqt4*-dev
libqt4* keep for all quads
libqt5*


# checkinstall : um aus dem Quelltext ein Debian-Paket (.deb) zu erstellen,

Desktop Rechner
apt-get install konsole kate libreoffice kcalc konqueror cifs-utils nfs-common lm-sensors im net-tools

Cluster
apt-get install flex build-essential libhwloc5 bclibnuma1 ganglia-monitor apt-file ipmitool libconfuse-dev

/etc/modules
ipmi_devintf

# timeserver
apt-get install ntpdate
$ cat /etc/cron.daily/ntp
#!/bin/sh
ntpdate time.fu-berlin.de

chmod +x /etc/cron.daily/ntp


# stuff you prob. want to deinstall
mlocale collectd*

Cluster Allgemein

Ergebnise Kopieren (need update)
$ rsync -aPz ergzus.bin ergqh.bin ergqhmax.bin *.nml *.txt fort.4242 abenheim3979.* hydstructs thomas@.ddns.net:/hastenichtgesehn/

MPI Debuggen

Startet fuer jeden Thread ein xterm Fenster.
--ex run Startet den Debugger


mpiexec  -n 16 xterm -e gdb -ex "run" --args  /home/kater/bin/unrunoff

Infiniband

Für die neuen Karten in quad21-26
81:00.0 Infiniband controller: Mellanox Technologies MT27600 [Connect-IB]

Firmeware update der Karte machen, Siehe https://www.thomas-krenn.com/de/wikiDE/index.php?title=Mellanox_Firmware_Tools_-_Firmware_Upgrade_unter_Linux&xtxsearchselecthit=1

mft-4.23.0-104-x86_64-deb.tgz runterladen, entpacken, installieren. Dafür folgende Pakete installieren:
apt-get install gcc make dkms linux-headers-5.10.0-19-amd64 libucx0 libgfortran5 libevent-pthreads-2.1-7 libevent-core-2.1-7 libhwloc15 htop

Mit mlxfwmanager Firmware Version feststellen
Neue Firmaware runterladen:
mlxfwmanager --download-os linux_x64 --download-type self_extractor -y
cd linux_x64/
linux_x64# ./mlxup
Versions: Current Available
FW 10.10.4020 10.16.1200
reboot
root@quad21:~# ibstatus
Infiniband device 'mlx5_0' port 1 status:
default gid: fe80:0000:0000:0000:e41d:2d03:000c:0c20
base lid: 0x4
sm lid: 0x1
state: 4: ACTIVE
phys state: 5: LinkUp
rate: 40 Gb/sec (4X FDR10)
link_layer: InfiniBand

====================================

https://wiki.debian.org/RDMA
Install rdma-core

Mellanox Technologies MT26428 Installation

apt-get install ibutils infiniband-diags perftest libmlx4-1 libmthca1 libipathverbs1 rdmacm-utils cpufrequtils ibverbs-utils infiniband-diags perftest firmware-linux-free
### neueres? älters? paket: ibverbs-providers

modprobe ib_umad ib_mthca mlx4_ib ib_uverbs ib_ipoib rdma_ucm mlx4_core (Module einzeln laden)

/etc/modules
ib_umad
ib_mthca
mlx4_ib
ib_uverbs
ib_ipoib
rdma_ucm 
mlx4_core

(Ne brauchen wir nicht)
Uses who want to run MPI jobs will need to have write permissions for the following devices:
The simplest way to do this is to add the users to the rdma group.

/dev/infiniband/uverbs*
/dev/infiniband/rdma_cm*
usermod -a -G rdma aron

OpenMPI will need to pin memory. Edit /etc/security/limits.conf and add the line:

* hard memlock unlimited 
* soft memlock unlimited 

# to ping start server and use port GUID from ibstat
ibping -S
ibping -G fe80::2:c903:10:5fa4
Pong from quad02.(none) (Lid 5): time 0.602 ms


Programme:
$ ibdiagnet
$ iblinkinfo
$ ibnetdiscover - to get lid
$ ibportstate to set links speed
lid port speed speed
speed is the speed of the port: 1 for 2.5 Gbyte/sec, 2 for 5.0 Gbyte/sec, and 4 for 10.0 Gbyte/sec.
ibportstate 14 1 speed 7
operation "enable" hilft um den link speed zu aktivieren
$ perfquery


Ganglia

IB plugin https://github.com/ULHPC/ganglia_infiniband_module
Damit ganglia perfquery ausführen kann ohne sudo
$ chmod u+s /usr/sbin/perfquery

Braucht Symlink von libconfuse.so.0
thomas@quad11:/usr/lib/x86_64-linux-gnu$ ll libconfuse.*
-rw-r--r-- 1 root root 51K Aug 15 2018 libconfuse.so.1.0.0
lrwxrwxrwx 1 root root 19 Aug 15 2018 libconfuse.so -> libconfuse.so.1.0.0
lrwxrwxrwx 1 root root 13 Jul 24 09:11 libconfuse.so.0 -> libconfuse.so

/etc/ganglia/gmond.conf

modules {
   module {
     name = "ib_module"
     language = "C/C++"
     path = "/root/modInfiniband.so"
  }
}

collection_group {
  collect_every = 20
  time_threshold = 60
  metric {
    name = "ib_bytes_out"
    value_threshold = 1000000000000
    title = "Bytes Sent(infiniband)"
  }
  metric {
    name = "ib_bytes_in"
    value_threshold = 1000000000000
    title = "Bytes Received(infiniband)"
  }
  metric {
    name = "ib_pkts_in"
    value_threshold = 100000000000
    title = "Packets Received(infiniband)"
  }
  metric {
    name = "ib_pkts_out"
    value_threshold = 100000000000
    title = "Packets Sent(infiniband)"
  }
}

crontab -e
* * * * * /home/thomas/bin/gmetric-cpu-temp.sh

Trouble
=======

[quad01:05373] Error: unknown option "--hnp-topo-sig"
Use full path for mpiexec and inka_kopplung

latency and bandwidth test
==========================
# make sure every CPU has the same FREQ because stupidity
for ((i=0; i<32;i++)); do cpufreq-set -g performance -c $i; done
# On one PC
ib_send_lat -a
# On other PC
ib_send_lat 192.168.20.112 -a
# Same for ib_send_bw
ib_send_lat -a 192.168.20.112 
---------------------------------------------------------------------------------------
                    Send Latency Test
 Dual-port       : OFF          Device         : mlx4_0
 Number of qps   : 1            Transport type : IB
 Connection type : RC           Using SRQ      : OFF
 TX depth        : 1
 Mtu             : 4096[B]
 Link type       : IB
 Max inline data : 236[B]
 rdma_cm QPs     : OFF
 Data ex. method : Ethernet
---------------------------------------------------------------------------------------
 local address: LID 0x07 QPN 0x0145 PSN 0x40bbdc
 remote address: LID 0x08 QPN 0x0127 PSN 0x625da0
---------------------------------------------------------------------------------------
 #bytes #iterations    t_min[usec]    t_max[usec]  t_typical[usec]
 2       1000          1.32           29.75        1.98   
 4       1000          1.24           15.99        1.54   
 8       1000          1.24           8.66         1.42   
 16      1000          1.19           11.14        1.40   
 32      1000          1.24           12.68        1.58   
 64      1000          1.37           13.84        1.66   
 128     1000          1.53           14.81        1.83   
 256     1000          3.08           33.22        5.29   
 512     1000          3.25           19.88        4.01   
 1024    1000          3.73           14.94        4.12   
 2048    1000          5.21           14.80        5.57   
 4096    1000          8.23           22.35        8.64   
 8192    1000          10.94          32.77        11.47  
 16384   1000          16.45          49.51        17.58  
 32768   1000          27.41          74.35        29.15  
 65536   1000          50.14          147.59       51.21  
 131072  1000          94.49          268.19       96.09  
 262144  1000          183.19         472.53       184.69 
 524288  1000          360.21         832.79       365.68 
 1048576 1000          714.91         1399.75      721.41 
 2097152 1000          1422.95        2865.38      1437.44
 4194304 1000          2840.72        4905.65      2907.37
 8388608 1000          5807.65        10473.58      5936.33
---------------------------------------------------------------------------------------

ib_send_bw 192.168.20.112  -a
---------------------------------------------------------------------------------------
                    Send BW Test
 Dual-port       : OFF          Device         : mlx4_0
 Number of qps   : 1            Transport type : IB
 Connection type : RC           Using SRQ      : OFF
 TX depth        : 128
 CQ Moderation   : 100
 Mtu             : 4096[B]
 Link type       : IB
 Max inline data : 0[B]
 rdma_cm QPs     : OFF
 Data ex. method : Ethernet
---------------------------------------------------------------------------------------
 local address: LID 0x07 QPN 0x0148 PSN 0xd4c92e
 remote address: LID 0x08 QPN 0x012a PSN 0x51f56e
---------------------------------------------------------------------------------------
 #bytes     #iterations    BW peak[MB/sec]    BW average[MB/sec]   MsgRate[Mpps]
 2          1000             7.64               5.88               3.080942
 4          1000             7.48               6.75               1.769229
 8          1000             48.74              42.44              5.562193
 16         1000             42.13              39.38              2.580683
 32         1000             170.37             140.12             4.591350
 64         1000             248.02             185.61             3.041025
 128        1000             92.72              55.54              0.454995
 256        1000             500.02             435.57             1.784099
 512        1000             1109.73            1050.87            2.152184
 1024       1000             1237.52            1217.68            1.246901
 2048       1000             1267.55            1251.44            0.640736
 4096       1000             1342.55            1336.95            0.342258
 8192       1000             1371.66            1354.30            0.173351
 16384      1000             1299.78            1183.89            0.075769
 32768      1000             1311.13            1302.48            0.041679
 65536      1000             1361.31            1361.30            0.021781
 131072     1000             1387.05            1281.65            0.010253
 262144     1000             1354.87            1291.06            0.005164
 524288     1000             1311.00            1297.36            0.002595
 1048576    1000             1344.04            1312.48            0.001312
 2097152    1000             1320.18            1312.31            0.000656
 4194304    1000             1349.24            1328.86            0.000332
 8388608    1000             1281.43            1281.43            0.000160
---------------------------------------------------------------------------------------

FTP

very secure ftp vsftp

chroot_local_user=YES
seccomp_sandbox=no
userlist_deny=NO
userlist_enable=YES
userlist_file=/etc/vsftpd.user_list
check_shell=NO
local_root=/srv/ftp/

Config Datein

# IPv6 deaktivieren
$ cat /etc/sysctl.d/01-disable-ipv6.conf
net.ipv6.conf.all.disable_ipv6 = 1

# sshd_config
PermitRootLogin no
StrictModes no
PubkeyAuthentication yes
PermitEmptyPasswords no
X11Forwarding yes

User Stuff

Sicherstellen, dass sich der User von jeden Quad auf jeden Quad automatisch einloggen kann. Da orted sich Baum-artig von Host zu Host einlogt.


adduser --uid 1001 thomas
addgroup --gid 998 quad
# Change default group of user
usermod -g quad aron
usermod -g quad thomas


## ~/.bashrc
# stupid systemd idiots
# Nein der Scheiss bewirkt absolut garnichts! Nur screen hilft.
#loginctl enable-linger $USER

#Change default file permission to rwx for directorys and files in
umask 0002


screen skript das immer die schon offenen session startet

#!/bin/sh

if [ $# -eq 0 ]; then
#echo "No arguments supplied"

if /usr/bin/screen -x; then
echo ""
else
/usr/bin/screen
fi
else
exec /usr/bin/screen "$@"
fi


# net quad00
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

# mpich debug
./configure --prefix=/home6/datahome/aroland/opt/mpich-3.2.1_gcc-7.2.0_dbg/ --enable-fortran=all --enable-g=all --enable-fast=O0 --enable-error-checking=all --enable-error-messages=all --enable-debuginfo

# netcdf hdf5
FC=/home/zanke/opt/openmpi_gfortran/bin/mpif90 CC=/home/zanke/opt/openmpi_gfortran/bin/mpicc ./configure --prefix=/home/zanke/opt/hdf5-1.8.19_gfortran6.3.0/ --enable-fortran --enable-fortran2003 --enable-parallel
make
make check

# netcdf
FC=/home/zanke/opt/openmpi_gfortran/bin/mpif90 CC=/home/zanke/opt/openmpi_gfortran/bin/mpicc CPPFLAGS=-I/home/zanke/opt/hdf5-1.8.19_gfortran6.3.0/include LDFLAGS=-L/home/zanke/opt/hdf5-1.8.19_gfortran6.3.0/lib ./configure --prefix=/home/zanke/opt/netcdf-4.4.1_gfortran6.3.0/

# netcdff
FC=/home/zanke/opt/openmpi_gfortran/bin/mpif90 CC=/home/zanke/opt/openmpi_gfortran/bin/mpicc CPPFLAGS=-I/home/zanke/opt/netcdf-4.4.1_gfortran6.3.0/include LDFLAGS=-L/home/zanke/opt/netcdf-4.4.1_gfortran6.3.0/lib ./configure --prefix=/home/zanke/opt/netcdf-4.4.1_gfortran6.3.0/

S.M.A.R.T

Wichtige Werte für nicht SSD Platten, die eine Langzeit Überwachung mit z.B. Ganglia brauchen IMO:
188 Command_Timeout
197 Current_Pending_Sector
198 Offline_Uncorrectable
5 Reallocated_Sector_Ct
187 Reported_Uncorrect
10 Spin_Retry_Count
199 UDMA_CRC_Error_Count

# smartctl -a /dev/sda | egrep "Command_Timeout|Current_Pending_Sector|Offline_Uncorrectable|Reallocated_Sector_Ct|Reported_Uncorrect|Spin_Retry_Count|UDMA_CRC_Error_Count"

29.10.2019

sda / /home

=== START OF INFORMATION SECTION ===
Device Model:     ST8000AS0002-1NA17Z
Serial Number:    Z840AG52
LU WWN Device Id: 5 000c50 08734ecdb
Firmware Version: AR15
User Capacity:    8,001,563,222,016 bytes [8.00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    5980 rpm
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   ACS-2, ACS-3 T13/2161-D revision 3b
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Tue Oct 29 06:59:44 2019 CET

SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   114   099   006    Pre-fail  Always       -       72037664
  3 Spin_Up_Time            0x0003   091   090   000    Pre-fail  Always       -       0
  4 Start_Stop_Count        0x0032   100   100   020    Old_age   Always       -       43
  5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000f   084   060   030    Pre-fail  Always       -       50041550840
  9 Power_On_Hours          0x0032   062   062   000    Old_age   Always       -       33792
 10 Spin_Retry_Count        0x0013   100   100   097    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   020    Old_age   Always       -       43
183 Runtime_Bad_Block       0x0032   100   100   000    Old_age   Always       -       0
184 End-to-End_Error        0x0032   100   100   099    Old_age   Always       -       0
187 Reported_Uncorrect      0x0032   100   100   000    Old_age   Always       -       0
188 Command_Timeout         0x0032   100   100   000    Old_age   Always       -       0
189 High_Fly_Writes         0x003a   091   091   000    Old_age   Always       -       9
190 Airflow_Temperature_Cel 0x0022   072   050   045    Old_age   Always       -       28 (Min/Max 28/36)
191 G-Sense_Error_Rate      0x0032   100   100   000    Old_age   Always       -       0
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       1180
193 Load_Cycle_Count        0x0032   095   095   000    Old_age   Always       -       11969
194 Temperature_Celsius     0x0022   028   050   000    Old_age   Always       -       28 (0 17 0 0 0)
195 Hardware_ECC_Recovered  0x001a   114   099   000    Old_age   Always       -       72037664
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       0
240 Head_Flying_Hours       0x0000   100   253   000    Old_age   Offline      -       31769 (216 109 0)
241 Total_LBAs_Written      0x0000   100   253   000    Old_age   Offline      -       43960187200
242 Total_LBAs_Read         0x0000   100   253   000    Old_age   Offline      -       35616462371

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed without error       00%     25167         -
# 2  Extended offline    Completed without error       00%     22711         -

sdb /perm

=== START OF INFORMATION SECTION ===
Device Model:     ST8000AS0002-1NA17Z
Serial Number:    Z840AMJ5
LU WWN Device Id: 5 000c50 08744d481
Firmware Version: AR15
User Capacity:    8,001,563,222,016 bytes [8.00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    5980 rpm
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   ACS-2, ACS-3 T13/2161-D revision 3b
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Tue Oct 29 07:00:52 2019 CET

SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   118   099   006    Pre-fail  Always       -       187522464
  3 Spin_Up_Time            0x0003   091   090   000    Pre-fail  Always       -       0
  4 Start_Stop_Count        0x0032   100   100   020    Old_age   Always       -       43
  5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000f   087   060   030    Pre-fail  Always       -       4888765593
  9 Power_On_Hours          0x0032   062   062   000    Old_age   Always       -       33791
 10 Spin_Retry_Count        0x0013   100   100   097    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   020    Old_age   Always       -       43
183 Runtime_Bad_Block       0x0032   100   100   000    Old_age   Always       -       0
184 End-to-End_Error        0x0032   100   100   099    Old_age   Always       -       0
187 Reported_Uncorrect      0x0032   100   100   000    Old_age   Always       -       0
188 Command_Timeout         0x0032   100   099   000    Old_age   Always       -       1
189 High_Fly_Writes         0x003a   100   100   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0022   071   049   045    Old_age   Always       -       29 (Min/Max 28/38)
191 G-Sense_Error_Rate      0x0032   100   100   000    Old_age   Always       -       0
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       289
193 Load_Cycle_Count        0x0032   088   088   000    Old_age   Always       -       25492
194 Temperature_Celsius     0x0022   029   051   000    Old_age   Always       -       29 (0 18 0 0 0)
195 Hardware_ECC_Recovered  0x001a   118   099   000    Old_age   Always       -       187522464
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       0
240 Head_Flying_Hours       0x0000   100   253   000    Old_age   Offline      -       22376 (153 118 0)
241 Total_LBAs_Written      0x0000   100   253   000    Old_age   Offline      -       96619086856
242 Total_LBAs_Read         0x0000   100   253   000    Old_age   Offline      -       63050316253

sdc /karten

=== START OF INFORMATION SECTION ===
Device Model:     ST8000AS0002-1NA17Z
Serial Number:    Z840AF12
LU WWN Device Id: 5 000c50 08735770e
Firmware Version: AR15
User Capacity:    8,001,563,222,016 bytes [8.00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    5980 rpm
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   ACS-2, ACS-3 T13/2161-D revision 3b
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Tue Oct 29 07:01:14 2019 CET

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   119   099   006    Pre-fail  Always       -       229844224
  3 Spin_Up_Time            0x0003   091   090   000    Pre-fail  Always       -       0
  4 Start_Stop_Count        0x0032   100   100   020    Old_age   Always       -       43
  5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000f   079   060   030    Pre-fail  Always       -       86831809
  9 Power_On_Hours          0x0032   062   062   000    Old_age   Always       -       33791
 10 Spin_Retry_Count        0x0013   100   100   097    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   020    Old_age   Always       -       43
183 Runtime_Bad_Block       0x0032   100   100   000    Old_age   Always       -       0
184 End-to-End_Error        0x0032   100   100   099    Old_age   Always       -       0
187 Reported_Uncorrect      0x0032   100   100   000    Old_age   Always       -       0
188 Command_Timeout         0x0032   100   100   000    Old_age   Always       -       0
189 High_Fly_Writes         0x003a   084   084   000    Old_age   Always       -       16
190 Airflow_Temperature_Cel 0x0022   072   055   045    Old_age   Always       -       28 (Min/Max 27/36)
191 G-Sense_Error_Rate      0x0032   100   100   000    Old_age   Always       -       0
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       28
193 Load_Cycle_Count        0x0032   084   084   000    Old_age   Always       -       33889
194 Temperature_Celsius     0x0022   028   045   000    Old_age   Always       -       28 (0 17 0 0 0)
195 Hardware_ECC_Recovered  0x001a   119   099   000    Old_age   Always       -       229844224
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       0
240 Head_Flying_Hours       0x0000   100   253   000    Old_age   Offline      -       18326 (15 246 0)
241 Total_LBAs_Written      0x0000   100   253   000    Old_age   Offline      -       21871056144
242 Total_LBAs_Read         0x0000   100   253   000    Old_age   Offline      -       3261163264

SWAP

fallocate -l 100G /home/swapfile
mkswap /home/swapfile
swapon /home/swapfile

debian/devuan vs BSD

Mein persönlicher Eindruck, wo einige Unterschiede sind.

* Bei D/D werden Log Datein regelmäßig gelöscht. Monatlich? Nach einem Reboot? Bei BSD ist die Grundeinstellung, dass auch nach Jahren Log Datein vorhanden sind. Gut, um längerfristige Veränderungen am System festzustellen. Von z.B. Hardware (Bus Errors), Malware

Festplatten testen

Zum testen von Festplatten nutze ich den destructiven Test von dem Programm badblocks. Die Festplatte wird dabei komplett vier mal überschrieben. Die SMART Werte der Festplatte speichere ich vor dem Testen mit badblocks ab und hinterher ein Vergleich zu machen.
Da das Programm badblocks im Falle von fehlerhaften Blöcken die Blocknummer auf die Konsole ausgibt und man bei vielen Ausgaben die Fortschrittsanzeige nicht mehr sieht, kann diese Ausgabe mit der -o Option in eine Datei umgeleitet werden.

Add -b 4096 for a larger blocksize for large (>= 6TB) devices.

badblocks -swv -o badblocks.txt /dev/sdb

Test with random data 131072*4096b = 512MB
badblocks -svw -b 4096 -o badblocks.txt -c 131072 -t random /dev/sdb

30.09.2015

c++11 move semantics - force it

Filed under: Allgemein — Tags: — Thomas @ 11:09

// $ g++ --std=c++11 -Wall -Wextra focemove.cpp
// $ ./a.out
// Yes using rvalue, move semantics
// Yes using rvalue, move semantics
// Oh no you forgot std::move somewhere. Deep copy occurs
//
// After delete unwanted ctor
// focemove.cpp: In function ‘void helper(std::vector< int >&&)’:
// focemove.cpp:44:20: error: use of deleted function ‘TestClass::TestClass(std::vector< int >&)’
// focemove.cpp:28:3: error: declared here
//
// testet with 4.7.4 - 5.2.1

#include < vector >
#include < iostream > 
#include < utility >

using namespace std;

// this class store biiiig data in a std::vector.
// If we initialize it with a const reference ctor a deep copy occurs.
// To prevent this, either dont proice a const reference ctor or better:
// forbid it at all.
class TestClass {
public:
  TestClass(vector< int > & other)
    : vec(other)
  {
    cout << "Oh no you forgot std::move somewhere. Deep copy occurs\n";
  }

// do we have to delete a const and non-const version here??
//   TestClass(const vector< int > & other) = delete;
//   TestClass(vector< int > & other) = delete;

  TestClass(vector< int > && other)
    : vec(other)
  {
    cout << "Yes using rvalue, move semantics\n";
  }
private:
  vector< int > vec;
};

void helper(vector< in t> && other) {
  // is other a rvalue or lvalue? It depends on the caller

  // here we forgot to use std::move(other)
  // other is a named rvalue and thus no move semantics are used
  TestClass a(other);

  // comment in this to test after fix TestClass constructor
//   TestClass a(move(other));
}

int main() {
  // this works all fine. All use move semantics
  TestClass(vector< int >());    // using temporaries, unnamed variables
  vector< int > other;
  TestClass(std::move(other)); // named variable other is converted to an unnamed with std::move

  // this call is okay
  helper(std::move(other));

  // this line triggers a error
  // cannot bind ‘std::vector< int >’ lvalue to ‘std::vector< int >&&’
  // helper(other);
  return 0;
}

« Newer PostsOlder Posts »

Powered by WordPress