0

我试图循环两个系列的变量,并用 R 统计软件制作它们以获得相关结果。

我很困惑为什么每次内部循环都完成时没有发生更大的循环(在 mica_headers 上)。

#!/bin/sh
#set -e


micaHeaderList="tot_instruction ILP32 ILP64 ILP128 ILP256 total_ins_count_for_hpc_alignment totInstruction mem-read mem-write control-flow arithmetic floating-point stack shift string sse other nop InstrFootprint64 InstrFootprint4k DataFootprint64 DataFootprint4k mem_access memReuseDist0-2 memReuseDist2-4 memReuseDist4-8 memReuseDist8-16 memReuseDist16-32 memReuseDist32-64 memReuseDist64-128 memReuseDist128-256 memReuseDist256-512 memReuseDist512-1k memReuseDist1k-2k memReuseDist2k-4k memReuseDist4k-8k memReuseDist8k-16k memReuseDist16k-32k memReuseDist32k-64k memReuseDist64k-128k memReuseDist128k-256k memReuseDist256k-512k memReuseDist512k-00 GAg_mispred_cnt_4bits PAg_mispred_cnt_4bits GAs_mispred_cnt_4bits PAs_mispred_cnt_4bits GAg_mispred_cnt_8bits PAg_mispred_cnt_8bits GAs_mispred_cnt_8bits PAs_mispred_cnt_8bits GAg_mispred_cnt_12bits PAg_mispred_cnt_12bits GAs_mispred_cnt_12bits PAs_mispred_cnt_12bits total_brCount total_transactionCount total_takenCount total_num_ops instr_reg_cnt total_reg_use_cnt total_reg_age reg_age_cnt_1 reg_age_cnt_2 reg_age_cnt_4 reg_age_cnt_8 reg_age_cnt_16 reg_age_cnt_32 reg_age_cnt_64 mem_read_cnt mem_read_local_stride_0 mem_read_local_stride_8 mem_read_local_stride_64 mem_read_local_stride_512 mem_read_local_stride_4096 mem_read_local_stride_32768 mem_read_local_stride_262144 mem_read_global_stride_0 mem_read_global_stride_8 mem_read_global_stride_64 mem_read_global_stride_512 mem_read_global_stride_4096 mem_read_global_stride_32768 mem_read_global_stride_262144 mem_write_cnt mem_write_local_stride_0 mem_write_local_stride_8 mem_write_local_stride_64 mem_write_local_stride_512 mem_write_local_stride_4096 mem_write_local_stride_32768 mem_write_local_stride_262144 mem_write_global_stride_0 mem_write_global_stride_8 mem_write_global_stride_64 mem_write_global_stride_512 mem_write_global_stride_4096 mem_write_global_stride_32768 mem_write_global_stride_262144"
mhToBeReplaced="ILP32"


compilerOptionList="funsafe_math_optimizations fno_guess_branch_probability fno_ivopts fno_tree_loop_optimize fno_inline_functions funroll_all_loops fno_omit_frame_pointer falign_jumps fselective_scheduling fno_inline_small_functions fno_tree_pre ftracer fno_move_loop_invariants"
coToBeReplaced="fno_guess_branch_probability"

for mica_header in $micaHeaderList
do

    for compiler_option in $compilerOptionList
    do

        echo "Calculating $compiler_option correlation for $mica_header"
        sed -i "s/$coToBeReplaced/$compiler_option/g" r.scr
        coToBeReplaced=$compiler_option
        make
    done


    sed -i "s/$mhToBeReplaced/$mica_header/g" r.scr
    mhToBeReplaced=$mica_header

done

编辑:一般来说,为了避免迭代值和源文件的值不一致,我怎么能把这两个从不同的文件链接在一起。即 micaHeaderList 与 ALL.scv 文件中的标题?

4

1 回答 1

0

在脚本中有一个错误,它回显了一个值,$mica_header该值将仅替换make下一个外部循环运行中的调用。这是由于第二个sed仅在make. 它应该在内部循环之前被调用。这不会引起混乱吗?

此外,与其将参数的一个值替换为另一个值,不如创建一个r.src带有占位符的文件模板,以便更改参数。通过这种方式,我们可以确保对于某些参数值,不会与搜索模式发生冲突,并且拼写错误不会阻止替换。

下面是一个改进的脚本,其代码相当简单。里面的部分if test "$Test" = 1只是一个被激活的测试代码Test=1。对于这个脚本,只需为r.scr命名创建一个模板r.scr.template并放置占位符%%MicaHeader%%%%CompilerOption%%而不是应该替换的参数。对于第一个测试,有一个较短的参数列表。

#!/bin/sh

micaHeaderList="tot_instruction ILP32 ILP64"
mhToBeReplaced=%%MicaHeader%%

compilerOptionList="funsafe_math_optimizations fno_guess_branch_probability fno_ivopts fno_tree_loop_optimize"
coToBeReplaced=%%CompilerOption%%

TemplateFile=r.scr.template
OutputFile=r.scr
Test=1

if test "$Test" = 1
then
    TemplateFile="${TemplateFile}-test"
    echo "$coToBeReplaced $mhToBeReplaced" >"$TemplateFile"
    make ()
    {
        echo -n ">>> make: "
        cat "$OutputFile"
    }
fi

for mica_header in $micaHeaderList
do
    for compiler_option in $compilerOptionList
    do
        echo "Calculating $compiler_option correlation for $mica_header"
        sed "s/$mhToBeReplaced/$mica_header/g;s/$coToBeReplaced/$compiler_option/g" "$TemplateFile" >"$OutputFile"
        make
    done
done

如果问题仍然存在:

  1. 检查生成的r.src文件。
  2. 检查make脚本是否真的使用r.src.
于 2013-09-10T02:43:36.463 回答