小编PKu*_*Kua的帖子

增加具有不同线程数的 2 个交替 OpenMP 并行区域的内存消耗

当我在具有不同线程数的 2 个 OpenMP 并行区域之间反复交替时,内存消耗会无限增加(数十 MB 甚至更多)。它甚至在这样一个简单的代码片段中也能做到这一点:

#include <unistd.h>

int main() {
    while (true) {
        #pragma omp parallel num_threads(16)
        usleep(30);

        #pragma omp parallel num_threads(8)
        usleep(30);
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

正如我在相关问题中已经发现的那样,在我的系统上,8 个线程一直被重用,而其余 8 个线程在每次进入 16 线程部分时新创建。虽然创建和销毁线程可能是 OpenMP 的预期行为,但不断增加的内存使用量看起来像是内存泄漏。对于具有相同线程数的 2 个部分,一切正常。有没有人知道这是什么原因,如果我坚持在每个部分使用不同数量的线程,我可以做什么?

我在 Ryzen 8 核 16 线程机器上使用 Ubuntu 18.04 和 GOMP 形式的 gcc 8.4.0(7.5.0 有同样的问题)。

这个问题是一个精简版的前一个问题做一个最小的工作例如避免不必要的信息。

c c++ multithreading memory-leaks openmp

5
推荐指数
0
解决办法
79
查看次数

强制最小JPanel大小

我正在尝试使用Java Swing为小型电话本应用程序编写布局.我遇到了一个我无法修复的大小问题.我希望过滤器(在搜索结果下显示)足够宽,以便在搜索短语很短时显示整个标题.这是它的样子:

样本过滤器

如你所见,名字缩短了.姓氏带有更长的文本,并按我的要求显示.

过滤类:

import javax.swing.*;
import javax.swing.border.CompoundBorder;
import java.awt.*;

public class Filter
{
    private JLabel label;
    private JPanel filterPane;

    Filter(String name)
    {
        // Filter text
        label = new JLabel();
        label.setForeground(new Color(0xAA0000));

        // Closing button
        JButton closeButton = new JButton("X");
        closeButton.setFont(new Font("Dialog", Font.BOLD, 20));
        closeButton.setMargin(new Insets(0, 0, 0, 0));

        filterPane = new JPanel();
        filterPane.setLayout(new BoxLayout(filterPane, BoxLayout.X_AXIS));
        // Frame with title + 50px padding on the right side for the next filter
        filterPane.setBorder(new CompoundBorder(
                BorderFactory.createEmptyBorder(0, 0, 0, 50),
                BorderFactory.createTitledBorder(name)));
        filterPane.add(closeButton);
        filterPane.add(Box.createRigidArea(new …
Run Code Online (Sandbox Code Playgroud)

java swing

2
推荐指数
1
解决办法
1188
查看次数

标签 统计

c ×1

c++ ×1

java ×1

memory-leaks ×1

multithreading ×1

openmp ×1

swing ×1