让我们假设我有一个(文本)文件具有以下结构(名称,分数):
a 0
a 1
b 0
c 0
d 3
b 2
Run Code Online (Sandbox Code Playgroud)
等等.我的目标是将每个名字的分数相加,并从最高分到最低分.所以在这种情况下,我想要以下输出:
d 3
b 2
a 1
c 0
Run Code Online (Sandbox Code Playgroud)
事先我不知道文件中会有什么名字.
我想知道是否有一种有效的方法来做到这一点.我的文本文件最多可包含50,000个条目.
我能想到的唯一方法就是从第1行开始,记住该名称,然后查看整个文件以查找该名称和总和.这看起来非常低效,所以我想知道是否有更好的方法来做到这一点.
我一直在尝试将 OpenMP 4.5 卸载安装到 gcc 的 Nvidia GPU 版本有一段时间,但到目前为止没有成功,尽管我越来越近了。
这一次,我按照这个脚本做了两个更改:首先我指定了gcc的trunk版本而不是7.2,其次nvptx-newlib现在根据github存储库包含在nvptx-tools中,所以我删除了那部分剧本。为了方便参考,原始脚本是
#!/bin/sh
#
# Build GCC with support for offloading to NVIDIA GPUs.
#
work_dir=$HOME/offload/wrk
install_dir=$HOME/offload/install
# Location of the installed CUDA toolkit
cuda=/usr/local/cuda
# Build assembler and linking tools
mkdir -p $work_dir
cd $work_dir
git clone https://github.com/MentorEmbedded/nvptx-tools
cd nvptx-tools
./configure \
--with-cuda-driver-include=$cuda/include \
--with-cuda-driver-lib=$cuda/lib64 \
--prefix=$install_dir
make
make install
cd ..
# Set up the GCC source tree
git clone https://github.com/MentorEmbedded/nvptx-newlib
svn co svn://gcc.gnu.org/svn/gcc/tags/gcc_7_2_0_release gcc
cd gcc
contrib/download_prerequisites …Run Code Online (Sandbox Code Playgroud)