Saturday, February 8, 2020

Retrieve data from a Map reverse-ordered by value and then ordered by key


Problem

Given a Map of strings to their frequencies. Find top N-most frequent strings. If there is a tie get lexicographically smallest names first.

Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
List<String> findTopNNames(Map<String, Integer> data, int n) {
    Comparator<Map.Entry<String, Integer>> cmpByValueDesc =
        Map.Entry.comparingByValue(Comparator.reverseOrder());

    Comparator<Map.Entry<String, Integer>> cmpByKey =
        Map.Entry.comparingByKey();

    Comparator<Map.Entry<String, Integer>> cmp =
        cmpByValueDesc.thenComparing(cmpByKey);

    return data.entrySet().stream()
        .sorted(cmp)
        .map(Map.Entry::getKey)
        .limit(n)
        .collect(Collectors.toList());
}

Tuesday, February 4, 2020

[WORKAROUND] Could not load GLX/OpenGL functions /usr/lib64/VirtualGL/libvglfaker.so: undefined symbol: glXGetProcAddressARB

I've encountered the following problem while starting IntelliJ IDEA via optirun:

$ optirun -c yuv ./idea-IC-193.5662.53/bin/idea.sh
...
[VGL] ERROR: Could not load GLX/OpenGL functions
[VGL] /usr/lib64/VirtualGL/libvglfaker.so: undefined symbol: glXGetProcAddressARB

Quick search gave me this link - https://github.com/VirtualGL/virtualgl/issues/102

Checked VirtualGL version:

$ rpm -qi VirtualGL
VirtualGL-2.5.2-4.fc31.x86_64

Added original VirtualGL yum repo according to https://virtualgl.org/Downloads/YUM

$ cat /etc/yum.repos.d/VirtualGL.repo 
[VirtualGL]
name=VirtualGL official RPMs
baseurl=https://sourceforge.net/projects/virtualgl/files
gpgcheck=1
gpgkey=https://sourceforge.net/projects/virtualgl/files/VGL-GPG-KEY
enabled=1
exclude=VirtualGL-*.*.9[0-9]-*

Thursday, January 30, 2020

[SOLVED] Cannot access secondary GPU - error: [XORG] (EE) Failed to load module "nvidia" (module does not exist, 0)

$ optirun -b none nvidia-settings -c :8
[   70.861063] [ERROR]Cannot access secondary GPU - error: [XORG] (EE) \
Failed to load module "nvidia" (module does not exist, 0)

[   70.861138] [ERROR]Aborting because fallback start is disabled.

The above is the problem I've encountered recently during NVIDIA proprietary driver installation on Fedora 31. Here're some details about a kernel and graphics card:

$ uname -r
5.4.13-201.fc31.x86_64

$ lspci -vnn | grep '\''[030[02]\]'
00:02.0 VGA compatible controller [0300]: Intel Corporation 3rd Gen Core \
processor Graphics Controller [8086:0166] (rev 09) (prog-if 00 [VGA controller])

01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK107M \
[GeForce GT 650M] [10de:0fd1] (rev ff) (prog-if ff)


I followed these instructions - https://docs.fedoraproject.org/en-US/quick-docs/bumblebee/index.html#_installation_nvidia_proprietary_driver. But after system restart "nvidia" module failed to load.

Here's a good troubleshooting page - https://github.com/Bumblebee-Project/Bumblebee/wiki/Troubleshooting. But there was nothing related to the mentioned error.

After reviewing bumblebee config I found out that "nvidia" module was actually missed:

$ grep "XorgModulePath" /etc/bumblebee/bumblebee.conf 
XorgModulePath=/usr/lib64/nvidia/xorg,/usr/lib64/xorg/modules

$ find /usr/lib64/xorg/modules -iname *nvidia*
$

Installing nvidia-driver and restarting the system solved the problem:

$ sudo dnf install nvidia-driver

$ find /usr/lib64/xorg/modules -iname *nvidia*
/usr/lib64/xorg/modules/drivers/nvidia_drv.so
/usr/lib64/xorg/modules/extensions/libglxserver_nvidia.so