--plus: {slot-1}/{seq-1} = {%}-1/{#}-1 (count from 0).

This commit is contained in:
Ole Tange 2024-01-04 23:27:21 +01:00
parent b2ef182897
commit fa129a592f
5 changed files with 135 additions and 121 deletions

View file

@ -504,6 +504,7 @@ env_parallel() {
`"
fi
export PARALLEL_ENV
# Free up some env space
unset _list_alias_BODIES _list_variable_VALUES _list_function_BODIES
unset _bodies_of_ALIASES _bodies_of_VARIABLES _bodies_of_FUNCTIONS
unset _names_of_ALIASES _names_of_VARIABLES _names_of_FUNCTIONS

View file

@ -2842,12 +2842,16 @@ sub init_globals() {
'{uniq}' => 'if(::uniq(@arg) != @arg) { skip(); }',
# {##} = number of jobs
'{##}' => '1 $_=total_jobs()',
# {0#} = 0-padded seq
'{0#}' => ('1 $f=1+int((log(total_jobs())/log(10)));'.
'$_=sprintf("%0${f}d",seq())'),
# {0%} = 0-padded jobslot
'{0%}' => ('1 $f=1+int((log($Global::max_jobs_running||1)/log(10)));'.
'$_=sprintf("%0${f}d",slot())'),
# {0%} = 0-padded seq
'{0#}' => ('1 $f=1+int((log(total_jobs())/log(10)));'.
'$_=sprintf("%0${f}d",seq())'),
# {seq-1} = seq-1 = counting from 0
'{seq(.*?)}' => '$_=eval q{$job->seq()}.qq{$$1}',
# {seq-1} = jobslot-1 = counting from 0
'{slot(.*?)}' => '$_=eval q{$job->slot()}.qq{$$1}',
## Bash inspired replacement strings
# Bash ${a:-myval}

View file

@ -2041,6 +2041,10 @@ B<{0%}> zero-padded jobslot.
B<{0#}> zero-padded sequence number.
B<{slot-1}> jobslot - 1 (i.e. counting from 0).
B<{seq-1}> sequence number - 1 (i.e. counting from 0).
B<{choose_k}> is inspired by n choose k: Given a list of n elements,
choose k. k is the number of input sources and n is the number of
arguments in an input source. The content of the input sources must
@ -2686,6 +2690,8 @@ The B<--plus> replacement strings are implemented as:
log(10))); $_=sprintf("%0${f}d",slot())'
--rpl '{0#} 1 $f=1+int((log(total_jobs())/log(10)));
$_=sprintf("%0${f}d",seq())'
--rpl '{seq(.*?)} $_=eval q{$job->seq()}.qq{$$1}'
--rpl '{slot(.*?)} $_=eval q{$job->slot()}.qq{$$1}'
--rpl '{:-([^}]+?)} $_ ||= $$1'
--rpl '{:(\d+?)} substr($_,0,$$1) = ""'

View file

@ -416,9 +416,12 @@ par_sshdelay() {
par_plus_slot_replacement() {
echo '### show {slot} {0%} {0#}'
parallel -k --plus 'sleep 0.{%};echo {slot}=$PARALLEL_JOBSLOT={%}' ::: A B C
parallel -j15 -k --plus 'echo Seq: {0#} {#}' ::: {1..100} | sort
parallel -j15 -k --plus 'sleep 0.{}; echo Slot: {0%} {%}' ::: {1..100} |
sort -u
doit() {
parallel -j15 -k --plus "$@" ::: {1..100} | sort -u
}
export -f doit
parallel doit ::: 'echo Seq: {0#} {#} {seq-1}*2={seq*2-2}' \
'sleep 0.{}; echo Slot: {0%} {%}={slot-1}+1'
}
par_replacement_slashslash() {

View file

@ -714,121 +714,121 @@ par_plus_slot_replacement ### show {slot} {0%} {0#}
par_plus_slot_replacement 1=1=1
par_plus_slot_replacement 2=2=2
par_plus_slot_replacement 3=3=3
par_plus_slot_replacement Seq: 001 1
par_plus_slot_replacement Seq: 002 2
par_plus_slot_replacement Seq: 003 3
par_plus_slot_replacement Seq: 004 4
par_plus_slot_replacement Seq: 005 5
par_plus_slot_replacement Seq: 006 6
par_plus_slot_replacement Seq: 007 7
par_plus_slot_replacement Seq: 008 8
par_plus_slot_replacement Seq: 009 9
par_plus_slot_replacement Seq: 010 10
par_plus_slot_replacement Seq: 011 11
par_plus_slot_replacement Seq: 012 12
par_plus_slot_replacement Seq: 013 13
par_plus_slot_replacement Seq: 014 14
par_plus_slot_replacement Seq: 015 15
par_plus_slot_replacement Seq: 016 16
par_plus_slot_replacement Seq: 017 17
par_plus_slot_replacement Seq: 018 18
par_plus_slot_replacement Seq: 019 19
par_plus_slot_replacement Seq: 020 20
par_plus_slot_replacement Seq: 021 21
par_plus_slot_replacement Seq: 022 22
par_plus_slot_replacement Seq: 023 23
par_plus_slot_replacement Seq: 024 24
par_plus_slot_replacement Seq: 025 25
par_plus_slot_replacement Seq: 026 26
par_plus_slot_replacement Seq: 027 27
par_plus_slot_replacement Seq: 028 28
par_plus_slot_replacement Seq: 029 29
par_plus_slot_replacement Seq: 030 30
par_plus_slot_replacement Seq: 031 31
par_plus_slot_replacement Seq: 032 32
par_plus_slot_replacement Seq: 033 33
par_plus_slot_replacement Seq: 034 34
par_plus_slot_replacement Seq: 035 35
par_plus_slot_replacement Seq: 036 36
par_plus_slot_replacement Seq: 037 37
par_plus_slot_replacement Seq: 038 38
par_plus_slot_replacement Seq: 039 39
par_plus_slot_replacement Seq: 040 40
par_plus_slot_replacement Seq: 041 41
par_plus_slot_replacement Seq: 042 42
par_plus_slot_replacement Seq: 043 43
par_plus_slot_replacement Seq: 044 44
par_plus_slot_replacement Seq: 045 45
par_plus_slot_replacement Seq: 046 46
par_plus_slot_replacement Seq: 047 47
par_plus_slot_replacement Seq: 048 48
par_plus_slot_replacement Seq: 049 49
par_plus_slot_replacement Seq: 050 50
par_plus_slot_replacement Seq: 051 51
par_plus_slot_replacement Seq: 052 52
par_plus_slot_replacement Seq: 053 53
par_plus_slot_replacement Seq: 054 54
par_plus_slot_replacement Seq: 055 55
par_plus_slot_replacement Seq: 056 56
par_plus_slot_replacement Seq: 057 57
par_plus_slot_replacement Seq: 058 58
par_plus_slot_replacement Seq: 059 59
par_plus_slot_replacement Seq: 060 60
par_plus_slot_replacement Seq: 061 61
par_plus_slot_replacement Seq: 062 62
par_plus_slot_replacement Seq: 063 63
par_plus_slot_replacement Seq: 064 64
par_plus_slot_replacement Seq: 065 65
par_plus_slot_replacement Seq: 066 66
par_plus_slot_replacement Seq: 067 67
par_plus_slot_replacement Seq: 068 68
par_plus_slot_replacement Seq: 069 69
par_plus_slot_replacement Seq: 070 70
par_plus_slot_replacement Seq: 071 71
par_plus_slot_replacement Seq: 072 72
par_plus_slot_replacement Seq: 073 73
par_plus_slot_replacement Seq: 074 74
par_plus_slot_replacement Seq: 075 75
par_plus_slot_replacement Seq: 076 76
par_plus_slot_replacement Seq: 077 77
par_plus_slot_replacement Seq: 078 78
par_plus_slot_replacement Seq: 079 79
par_plus_slot_replacement Seq: 080 80
par_plus_slot_replacement Seq: 081 81
par_plus_slot_replacement Seq: 082 82
par_plus_slot_replacement Seq: 083 83
par_plus_slot_replacement Seq: 084 84
par_plus_slot_replacement Seq: 085 85
par_plus_slot_replacement Seq: 086 86
par_plus_slot_replacement Seq: 087 87
par_plus_slot_replacement Seq: 088 88
par_plus_slot_replacement Seq: 089 89
par_plus_slot_replacement Seq: 090 90
par_plus_slot_replacement Seq: 091 91
par_plus_slot_replacement Seq: 092 92
par_plus_slot_replacement Seq: 093 93
par_plus_slot_replacement Seq: 094 94
par_plus_slot_replacement Seq: 095 95
par_plus_slot_replacement Seq: 096 96
par_plus_slot_replacement Seq: 097 97
par_plus_slot_replacement Seq: 098 98
par_plus_slot_replacement Seq: 099 99
par_plus_slot_replacement Seq: 100 100
par_plus_slot_replacement Slot: 01 1
par_plus_slot_replacement Slot: 02 2
par_plus_slot_replacement Slot: 03 3
par_plus_slot_replacement Slot: 04 4
par_plus_slot_replacement Slot: 05 5
par_plus_slot_replacement Slot: 06 6
par_plus_slot_replacement Slot: 07 7
par_plus_slot_replacement Slot: 08 8
par_plus_slot_replacement Slot: 09 9
par_plus_slot_replacement Slot: 10 10
par_plus_slot_replacement Slot: 11 11
par_plus_slot_replacement Slot: 12 12
par_plus_slot_replacement Slot: 13 13
par_plus_slot_replacement Slot: 14 14
par_plus_slot_replacement Slot: 15 15
par_plus_slot_replacement Seq: 001 1 0*2=0
par_plus_slot_replacement Seq: 002 2 1*2=2
par_plus_slot_replacement Seq: 003 3 2*2=4
par_plus_slot_replacement Seq: 004 4 3*2=6
par_plus_slot_replacement Seq: 005 5 4*2=8
par_plus_slot_replacement Seq: 006 6 5*2=10
par_plus_slot_replacement Seq: 007 7 6*2=12
par_plus_slot_replacement Seq: 008 8 7*2=14
par_plus_slot_replacement Seq: 009 9 8*2=16
par_plus_slot_replacement Seq: 010 10 9*2=18
par_plus_slot_replacement Seq: 011 11 10*2=20
par_plus_slot_replacement Seq: 012 12 11*2=22
par_plus_slot_replacement Seq: 013 13 12*2=24
par_plus_slot_replacement Seq: 014 14 13*2=26
par_plus_slot_replacement Seq: 015 15 14*2=28
par_plus_slot_replacement Seq: 016 16 15*2=30
par_plus_slot_replacement Seq: 017 17 16*2=32
par_plus_slot_replacement Seq: 018 18 17*2=34
par_plus_slot_replacement Seq: 019 19 18*2=36
par_plus_slot_replacement Seq: 020 20 19*2=38
par_plus_slot_replacement Seq: 021 21 20*2=40
par_plus_slot_replacement Seq: 022 22 21*2=42
par_plus_slot_replacement Seq: 023 23 22*2=44
par_plus_slot_replacement Seq: 024 24 23*2=46
par_plus_slot_replacement Seq: 025 25 24*2=48
par_plus_slot_replacement Seq: 026 26 25*2=50
par_plus_slot_replacement Seq: 027 27 26*2=52
par_plus_slot_replacement Seq: 028 28 27*2=54
par_plus_slot_replacement Seq: 029 29 28*2=56
par_plus_slot_replacement Seq: 030 30 29*2=58
par_plus_slot_replacement Seq: 031 31 30*2=60
par_plus_slot_replacement Seq: 032 32 31*2=62
par_plus_slot_replacement Seq: 033 33 32*2=64
par_plus_slot_replacement Seq: 034 34 33*2=66
par_plus_slot_replacement Seq: 035 35 34*2=68
par_plus_slot_replacement Seq: 036 36 35*2=70
par_plus_slot_replacement Seq: 037 37 36*2=72
par_plus_slot_replacement Seq: 038 38 37*2=74
par_plus_slot_replacement Seq: 039 39 38*2=76
par_plus_slot_replacement Seq: 040 40 39*2=78
par_plus_slot_replacement Seq: 041 41 40*2=80
par_plus_slot_replacement Seq: 042 42 41*2=82
par_plus_slot_replacement Seq: 043 43 42*2=84
par_plus_slot_replacement Seq: 044 44 43*2=86
par_plus_slot_replacement Seq: 045 45 44*2=88
par_plus_slot_replacement Seq: 046 46 45*2=90
par_plus_slot_replacement Seq: 047 47 46*2=92
par_plus_slot_replacement Seq: 048 48 47*2=94
par_plus_slot_replacement Seq: 049 49 48*2=96
par_plus_slot_replacement Seq: 050 50 49*2=98
par_plus_slot_replacement Seq: 051 51 50*2=100
par_plus_slot_replacement Seq: 052 52 51*2=102
par_plus_slot_replacement Seq: 053 53 52*2=104
par_plus_slot_replacement Seq: 054 54 53*2=106
par_plus_slot_replacement Seq: 055 55 54*2=108
par_plus_slot_replacement Seq: 056 56 55*2=110
par_plus_slot_replacement Seq: 057 57 56*2=112
par_plus_slot_replacement Seq: 058 58 57*2=114
par_plus_slot_replacement Seq: 059 59 58*2=116
par_plus_slot_replacement Seq: 060 60 59*2=118
par_plus_slot_replacement Seq: 061 61 60*2=120
par_plus_slot_replacement Seq: 062 62 61*2=122
par_plus_slot_replacement Seq: 063 63 62*2=124
par_plus_slot_replacement Seq: 064 64 63*2=126
par_plus_slot_replacement Seq: 065 65 64*2=128
par_plus_slot_replacement Seq: 066 66 65*2=130
par_plus_slot_replacement Seq: 067 67 66*2=132
par_plus_slot_replacement Seq: 068 68 67*2=134
par_plus_slot_replacement Seq: 069 69 68*2=136
par_plus_slot_replacement Seq: 070 70 69*2=138
par_plus_slot_replacement Seq: 071 71 70*2=140
par_plus_slot_replacement Seq: 072 72 71*2=142
par_plus_slot_replacement Seq: 073 73 72*2=144
par_plus_slot_replacement Seq: 074 74 73*2=146
par_plus_slot_replacement Seq: 075 75 74*2=148
par_plus_slot_replacement Seq: 076 76 75*2=150
par_plus_slot_replacement Seq: 077 77 76*2=152
par_plus_slot_replacement Seq: 078 78 77*2=154
par_plus_slot_replacement Seq: 079 79 78*2=156
par_plus_slot_replacement Seq: 080 80 79*2=158
par_plus_slot_replacement Seq: 081 81 80*2=160
par_plus_slot_replacement Seq: 082 82 81*2=162
par_plus_slot_replacement Seq: 083 83 82*2=164
par_plus_slot_replacement Seq: 084 84 83*2=166
par_plus_slot_replacement Seq: 085 85 84*2=168
par_plus_slot_replacement Seq: 086 86 85*2=170
par_plus_slot_replacement Seq: 087 87 86*2=172
par_plus_slot_replacement Seq: 088 88 87*2=174
par_plus_slot_replacement Seq: 089 89 88*2=176
par_plus_slot_replacement Seq: 090 90 89*2=178
par_plus_slot_replacement Seq: 091 91 90*2=180
par_plus_slot_replacement Seq: 092 92 91*2=182
par_plus_slot_replacement Seq: 093 93 92*2=184
par_plus_slot_replacement Seq: 094 94 93*2=186
par_plus_slot_replacement Seq: 095 95 94*2=188
par_plus_slot_replacement Seq: 096 96 95*2=190
par_plus_slot_replacement Seq: 097 97 96*2=192
par_plus_slot_replacement Seq: 098 98 97*2=194
par_plus_slot_replacement Seq: 099 99 98*2=196
par_plus_slot_replacement Seq: 100 100 99*2=198
par_plus_slot_replacement Slot: 01 1=0+1
par_plus_slot_replacement Slot: 02 2=1+1
par_plus_slot_replacement Slot: 03 3=2+1
par_plus_slot_replacement Slot: 04 4=3+1
par_plus_slot_replacement Slot: 05 5=4+1
par_plus_slot_replacement Slot: 06 6=5+1
par_plus_slot_replacement Slot: 07 7=6+1
par_plus_slot_replacement Slot: 08 8=7+1
par_plus_slot_replacement Slot: 09 9=8+1
par_plus_slot_replacement Slot: 10 10=9+1
par_plus_slot_replacement Slot: 11 11=10+1
par_plus_slot_replacement Slot: 12 12=11+1
par_plus_slot_replacement Slot: 13 13=12+1
par_plus_slot_replacement Slot: 14 14=13+1
par_plus_slot_replacement Slot: 15 15=14+1
par_process_slot_var ### bug #62310: xargs compatibility: --process-slot-var=name
par_process_slot_var 0
par_process_slot_var 1