ANI: a dataflow program model

2 views
Skip to first unread message

Eric.Lu

unread,
Jan 19, 2010, 8:22:40 PM1/19/10
to computer.paraopt.compiler
Introduction
anic is the reference implementation ompiler for the experimental,
high-performance, statically-safe, fully implicitly parallel, object-
oriented, general-purpose dataflow programming language ANI.
Portably written using the GNU toolchain, anic works on all of the
popular operating systems, including *nix, Mac OS X, and Windows (via
Cygwin).
anic:是一个实验性质的编译器,为具有high-performance、statically-safe、fully implicitly
parallel, object-oriented特点的通用的数据流编程语言ANI服务。
The project is free and open; you can get a copy of the anic source
anytime:
hg clone https://anic.googlecode.com/hg/ anic
1.1 The Fast Track
Want to get started with ANI programming right away? Head over
straight to the ANI Tutorial.
Got burning philosophical questions? The FAQ is this way.
Have something to say? Join in on the official discussion group.
Want to know more about the project? Read on.
1.2 The Quirks(巨变)
ANI is probably unlike any programming language you've encountered; it
does away with state, variables, commands, stacks, and memory itself,
as we know it. In ANI, the compiler sequences the ordering of your
program logic for you, laying out as much of it as possible in
parallel, and guaranteeing that the resulting binary will be
statically safe and deadlock-free. Best of all, compiler technology
has advanced to the point where you don't need to understand any of
this to leverage it; that's anic's job!
ANI可能不同于你以前所见到的任何编程语言;它没有state, variable, commands, stacks, and
memory itself。在ANI语言中,编译器为你控制程序中逻辑顺序,并尽可能多的程序区域并行化并且保证生成的二进制代码是
statically safe and deadlock-free。目前的编译器技术已经能够做到这点,所以程序员不用管负责这些工作,都是
anic的工作。
Crazy? Most definitely. And yet strangely enough, it works!
Hello, World!
The language couldn't possibly be simpler...
这个语言已经不可能再简单了?!
"Hello, World!" ->std.out
1.3 Dining Philosophers Problem - A Complete, Well-Written, Correct
Program(哲学家就餐问题)
...or any more powerful...
philosopher = [[int id]] {
chopstick = [[int\]] <- 0;
leftPhil = [[philosopher]];
rightPhil = [[philosopher]];

getChopsticks = [[--> int\, int\]] { \leftPhil.chopstick,
\rightPhil.chopstick --> };
returnChopsticks = [[int\ cs1, int\ cs2]] { \cs1 -
>leftPhil.chopstick; \cs2 ->rightPhil.chopstick; };
eat = [[int\ cs1, int\ cs2 --> int\, int\]] {
"Philosopher " + id + " eating...\n" ->std.out;
\cs1, \cs2 -->;
};

loopback => std.rand std.delay \getChopsticks eat -
>returnChopsticks loopback;
};

numPhils = 5;

philStream = [[philosopher\\]];
\\[[std.gen]] <- numPhils {
[[philosopher]] <- {..} ->philStream;
philStream[..] ->philStream[..].leftPhil;
philStream[(.. + 1) % numPhils] ->philStream[..].rightPhil;
};
(for a more detailed explanation of why this works, see the FAQ)
Compare this with Wikipedia's much longer, much less efficient, and
unintuitive Pascal solution to the problem -- and that's actually a
"simple" solution leaning on high-level monitor constructions. For the
real nightmare, try implementing this thing using pthreads (the
industry standard). Given half an hour and some frustration, a well-
experienced programmer could probably do it.
But why? There's ANI.
与wikipedia上的更长、效率更差而且不直观的pascal解决方案解决该问题,-----这的确是偏于高级管理问题的“简洁”的解决方
案。用 pthreads的方法解决该类问题真是一个午夜噩梦。在经过挫折花费了半个小时的时间后,有很好经验的程序员或许可以解决这个问题。
1.4 The Aim(目标)
Try to imagine, if you will, the amount of time and effort it would
take you to write a bug-free, efficiently multithreaded real-time
clock + infix calculator hybrid application in a language like C.
如果你乐意,试着去想象下,只需要写一个c语言程序的时间,你就能实现一个没有bug,高效的多线程real-time clock+infix
calculator hybrid 应用程序。
While you're thinking, here's a terse but 100% complete implementation
in ANI:
你还想这个问题么,下面是一个简洁但是100%完整的ANI实现
@std.in;
a=[[0\]]; op=[[' '\]]; b=[[0\]]; r=[[0\]];
0 { clock => [[int ms]] { ("\r" + ms/1000.0 + ":" + a + op + b + "=" +
r) ->std.out; 1 std.delay (ms+1) clock} };
inLoop => {\in->a \in->op \in->b inLoop};
\\op ?? {'+': (\a+\b) '-': (\a-\b) '*': (\a*\b) '/': (\a/\b) : 0} ->r;
ANI is an attempt to fuse the intuitive feel of shell scripting (and
all of its perks like implicit parallelism) with the safety of strict
compilation and the speed of hand-optimized parallel assembly: in
other words, lightweight programming that runs even faster than
typical C.
ANI是综合intuitive of shell scripting(并且所有的特色是隐式并行)具有satety of strict
compilation和手工优化的并行汇编的速度:换句话说,轻量级编程但是甚至具有比典型C程序更快的速度。
In short, ANI seeks to break out of the shackles of imperative
programming -- a stale paradigm which for four decades has produced
hundreds of clones of the same fundamental feature set, none of which
offer intuitive hands-off concurrency, and differing only in what
lengths they go to to sugar-coat the embarrassing truth that they're
all just increasingly high-level assemblers at heart; ANI is inspired
by the realization that in today's programming environment, your
compiler should be doing more for you than a blind language
translation!
总而言之,ANI试图打破命令编程的桎梏—— 一种已经40年并且产生了成百上千个基于同样原理的特征集合的陈旧范式,但是这些特征集合从来没有提供直
觉的不用手工优化的并发,只是在长度上不同的并掩盖了都只是不断增加的高层汇编的本质;ANI出现于现在的编程环境,编译器应该做的更多而不只是盲目的
进行语言翻译。
1.5 The Bottom Line(底线)
Think of ANI as a way to write fast, statically-guaranteed safe, well-
structured, and highly parallelized software without ever encountering
memory management, threads, locks, semaphores, critical sections, race
conditions, or deadlock.
把ANI看成是能够写出高性能、静态保证安全、良好结构的、并具有高度并行软件而不用考虑内存管理、线程、锁、信号量、临界区、数据竞争条件或者死
锁。
The central philosophy of ANI programming is that you "type-and-
forget". You describe what you want to happen to your data, and it
just gets done -- and fast. ANI is lightweight like a shell script but
fast like C, safe like Java, and implicitly massively parallel like a
language for the parallel processing age should be.
ANI的核心设计哲学是你“输入并忘记”。你描述出想要对数据所做的处理,然后这些处理就会发生而且快速的处理完。ANI是拥有shell脚本语言的轻
量级,但是有C速度,java的安全性,而且具有并行处理时代的隐式大规模并行能力。
ANI accomplishes these ambitious goals by way of two novel approaches:
• a paradigm shift away from the intractable chaos of imperative-
style memory twiddling in favor of structured but flexible dataflow
pipelines that can be heavily optimized through static analysis, and
• a paper-thin but extremely powerful micro-scheduling runtime that
exploits experimental ideas such as dynamic code polymorphism to
deliver fine-grained, safe, and fully implicit parallelism from the
compiled pipelines
ANI通过下面的两个创新实现了上述野心勃勃的目标:
 提出一个范例,去掉了命令式存储操作造成的难以控制的混乱,利用结构化的并且灵活的数据流管道,这些管道能够通过静态分析被深度优化的特
点。
 极薄但是非有强大的微调度运行时,运行时能够挖掘一些实验性质的方法例如动态代码多态发掘出细粒度、安全并完全的隐式并行性通过编译这些管道
(流水?)。

Reply all
Reply to author
Forward
0 new messages