690 - Pipeline Scheduling
2015-07-20 20:18
288 查看
Pipeline Scheduling
An arithmetic pipeline is designed to process more than one task simultaneously in an overlap- ping manner. It includes function units and data paths among them. Tasks are processed by pipelining; at each clock, one or more units are dedicated to a task and the output produced for the task at the clock is cascading to the units that are responsible for the next stage; since each unit may work in parallel with the others at any clock, more than one task may be being processed at a time by a single pipeline.
In this problem, a pipeline may have a feedback structure, that is, data paths among function units may have directed loops as shown in the next figure.
Example of a feedback pipeline
Since an arithmetic pipeline in this problem is designed as special purpose dedicated hardware, we assume that it accepts just a single sort of task. Therefore, the timing information of a pipeline is fully described by a simple table called a reservation table, which specifies the function units that are busy at each clock when a task is processed without overlapping execution.
Example of “reservation table”
clock 0 1 2 3 4 5 6
unit0 X . . . X X .
unit1 . X . . . . .
unit2 . . X . . . .
unit3 . . . X . . .
unit4 . . . . . . X
In reservation tables,
Notice that no special hardware is provided to avoid simultaneous use of the same function unit.
Therefore, a task must not be started if it would conflict with any tasks being processed. For instance, with the above reservation table, if two tasks, say task 0 and task 1, were started at clock 0 and clock 1, respectively, a conflict would occur on unit0 at clock 5. This means that you should not start two tasks with single cycle interval. This invalid schedule is depicted in the following process table, which is obtained by overlapping two copies of the reservation table with one being shifted to the right by 1 clock.
Example of “conflict”
clock 0 1 2 3 4 5 6 7
unit0 0 1 . . 0 C 1 .
unit1 . 0 1 . . . . .
unit2 . . 0 1 . . . .
unit3 . . . 0 1 . . .
unit4 . . . . . . 0 1
(
Your job is to write a program that reports the minimum number of clock cycles in which the given pipeline can process 10 tasks.
Input
The input consists of multiple data sets, each representing the reservation table of a pipeline. A data set is given in the following format.
The integer n(< 20) in the first line is the width of the reservation table, or the number of clock cycles that is necessary to perform a single task. The second line represents the usage of unit0, the third line unit1, and so on. xi,j is either
Output
For each data set, your program should output a line containing an integer number that is the minimum number of clock cycles in which the given pipeline can process 10 tasks.
Sample Input
7
X…XX.
.X…..
..X….
…X…
……X
0
Sample Output
34
Miguel A. Revilla
1999-03-05
我有话说:
这是一道位运算辅助dfs的搜索。
代码写的很简洁。
An arithmetic pipeline is designed to process more than one task simultaneously in an overlap- ping manner. It includes function units and data paths among them. Tasks are processed by pipelining; at each clock, one or more units are dedicated to a task and the output produced for the task at the clock is cascading to the units that are responsible for the next stage; since each unit may work in parallel with the others at any clock, more than one task may be being processed at a time by a single pipeline.
In this problem, a pipeline may have a feedback structure, that is, data paths among function units may have directed loops as shown in the next figure.
Example of a feedback pipeline
Since an arithmetic pipeline in this problem is designed as special purpose dedicated hardware, we assume that it accepts just a single sort of task. Therefore, the timing information of a pipeline is fully described by a simple table called a reservation table, which specifies the function units that are busy at each clock when a task is processed without overlapping execution.
Example of “reservation table”
clock 0 1 2 3 4 5 6
unit0 X . . . X X .
unit1 . X . . . . .
unit2 . . X . . . .
unit3 . . . X . . .
unit4 . . . . . . X
In reservation tables,
X' means ``the function unit is busy at that clock'' and.’ means “the function unit is not busy at that clock.” In this case, once a task enters the pipeline, it is processed by unit0 at the first clock, by unit1 at the second clock, and so on. It takes seven clock cycles to perform a task.
Notice that no special hardware is provided to avoid simultaneous use of the same function unit.
Therefore, a task must not be started if it would conflict with any tasks being processed. For instance, with the above reservation table, if two tasks, say task 0 and task 1, were started at clock 0 and clock 1, respectively, a conflict would occur on unit0 at clock 5. This means that you should not start two tasks with single cycle interval. This invalid schedule is depicted in the following process table, which is obtained by overlapping two copies of the reservation table with one being shifted to the right by 1 clock.
Example of “conflict”
clock 0 1 2 3 4 5 6 7
unit0 0 1 . . 0 C 1 .
unit1 . 0 1 . . . . .
unit2 . . 0 1 . . . .
unit3 . . . 0 1 . . .
unit4 . . . . . . 0 1
(
0's and1’s in this table except those in the first row represent tasks 0 and 1, respectively, and `C’ means the conflict.)
Your job is to write a program that reports the minimum number of clock cycles in which the given pipeline can process 10 tasks.
Input
The input consists of multiple data sets, each representing the reservation table of a pipeline. A data set is given in the following format.
The integer n(< 20) in the first line is the width of the reservation table, or the number of clock cycles that is necessary to perform a single task. The second line represents the usage of unit0, the third line unit1, and so on. xi,j is either
X' or.’. The former means reserved and the latter free. There are no spaces in any input line. For simplicity, we only consider those pipelines that consist of 5 function units. The end of the input is indicated by a data set with 0 as the value of n.
Output
For each data set, your program should output a line containing an integer number that is the minimum number of clock cycles in which the given pipeline can process 10 tasks.
Sample Input
7
X…XX.
.X…..
..X….
…X…
……X
0
Sample Output
34
Miguel A. Revilla
1999-03-05
我有话说:
这是一道位运算辅助dfs的搜索。
代码写的很简洁。
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N=5; const int M=100; int n,c,ans,w ,jump[M]; bool judge(int* s,int k) { for(int i=0;i<N;i++) if((s[i]>>k)&w[i])return false;//如果和前一个冲突 return true; } void Init() { char s[M]; c=0; ans=10*n; memset(w,0,sizeof(w));//清零 for(int i=0;i<N;i++) { scanf("%s",s); for(int j=0;j<n;j++) { if(s[j]=='X') w[i]|=(1<<j); } } for(int i=0;i<=n;i++) { if(judge(w,i))jump[c++]=i;//剪枝1:事先枚举能够放的位置。当然是在最理想的状态下只有一个未完进程。 } } void dfs(int* s,int d,int sum) { if(sum+(10-d)*jump[0]>ans)return;//剪枝2:如果目前最优情况比ans大直接剪枝 if(d==10){ ans=min(sum,ans); return; } for(int i=0;i<c;i++) { if(judge(s,jump[i])){ int p ; for(int j=0;j<N;j++) p[j]=(s[j]>>jump[i])^w[j]; dfs(p,d+1,sum+jump[i]); } } } int main() { while(scanf("%d",&n)==1&&n) { Init(); dfs(w,1,n); printf("%d\n",ans); } return 0; }
相关文章推荐
- topcoder decode
- Snail—OC学习之可变字符串NSMutableString
- uva 10361(字符串)
- 组合数
- 获得当前打开的窗口标题
- JavaScript页面的简单运算
- Android清单文件详解(六) ---- <activity>节点的属性
- Codeforces 432E Square Tiling(结构体+贪婪)
- UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 0: illegal multibyte sequence
- 可伸缩Web架构与分布式系统
- (七十七)地理编码与反地理编码
- 大数阶乘
- java jvm内存
- iOS开发笔记---SDWebImage分析
- javase学习之路--多态的形成以作用
- android桌面图标更换后不起效果
- HDOJ N皇后问题 2553【回溯搜索】
- (七十七)地理编码与反地理编码
- 在Python中怎么表达True
- ios 音乐播放