并行编程模型 新丁 ANIC

  昨天在CSDN上看到了关于 ANIC的新闻,anic是一个处于开发过程中开源项目,建立在google code上,其讨论在google group上,但由于政府的负责任 ,已经登录不上去了,所以只看到其部分内容。

  被其吸引是因为其号称“比C快、比java安全,比脚本简单”,最近一直在考虑编程模型,在由重核搭建的集群上,如何容易的写出高性能的并行程序是目前HPC领域的一个重大挑战,即使在网络应用方面由于多核、时代的到来,如何利用好多核加速自己的应用程序,也是非常现实的问题。MPI、OpenMP或者 MPI+OpenMP是目前的主流技术方案,但是MPI程序写起来困难、调试也困难,至于正确性验证也没有好的解决方案。我们目前希望在UPC的基础上,衍生出适合重核异构集群的编程模型,但是目前来看,在性能上也面临着巨大挑战,而且在实际应用中upc没有被很多用户接受。而且upc从根本上讲其在编程性上只是减少了一些繁琐工作,在难度上并没有降低,例如同步、一致性、依赖与数据竞争等问题依然需要程序员自己保证。

  所以,看到anic后,特别是看到其introduction后,觉得如果真如其所说,则是非常漂亮的解决方案,但是在看了其Tutorial后,由于写的不完整,还没有体会到其在介绍中说的优点。现在将其内容放在后面,供大家欣赏,本想翻译成中文,奈何没有时间,有机会再说吧。

---------------------------------------------------

http://code.google.com/p/anic/

 

Introduction

anic is the reference implementation compiler 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).

The Fast Track

Want to get started with ANI 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 ANI discussion group.

Ready to dive straight into the source? Go right ahead.

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!

Crazy? Most definitely. And yet strangely enough, it works!

Hello, World!

The language couldn't possibly be simpler...

"Hello, World!" ->std.out

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.

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.

While you're thinking, here's a terse but complete implementation in 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.

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!

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.

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 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

Warning: Computer Science Content!

To those more technically inclined, anic compiles source-specified pipeline definitions down to object code modules, which are linked with a runtime providing initialization code and a root arbitrator thread; the arbitrator spawns worker threads which are dynamically dispatched to the compiled pipelines in such a way that there are no memory conflicts.

Think of ANI source code as a blueprint for a set of train tracks. anic looks at this and builds a real train track for you (making it better wherever it can). The program is run by putting running trains onto the tracks, and it turns out that anic also hired a system administrator for you who will keep an eye on the trains to make sure they don't crash. That's ANI in a technical nutshell!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值