找回密码
 注册
Simdroid-非首页
查看: 419|回复: 20

[原创短文] ( 编译 Mandelbrot ) / 并行 = n 秒 ?

[复制链接]
发表于 2009-9-8 13:28:41 | 显示全部楼层 |阅读模式 来自 江苏无锡
本帖最后由 FreddyMusic 于 2009-9-8 14:22 编辑

( 编译 Mandelbrot ) / 并行 = n 秒 ?



游客,如果您要查看本帖隐藏内容请回复

[/hide]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
发表于 2009-9-8 14:01:29 | 显示全部楼层 来自 黑龙江哈尔滨
Simdroid开发平台
1# FreddyMusic

Mandelbrot 编译? 分形? 多少次迭代用了2秒?绘图时多少个点? 机器大概配置?

凑个热闹


  1. with(DocumentTools):
  2. kernelopts( gcfreq=10^7 ):
  3. # Computes number of iterations it takes for each point in a strip of the complex plane to escape (if at all)
  4. # from the Mandelbrot set. Stops when the absolute value of the iterate is greater than the bailout value,
  5. # or when the maximum number of iterations is exceeded.  Operates inplace on imageArray.
  6. MandelLoop := proc( X, Y, imageArray, i_low, i_high, j_low, j_high, iter, bailout )
  7.     local i, j, Xc, Yc, Xtemp, Ytemp, Xold, Yold, k;
  8.     option hfloat;
  9.     for i from i_low to i_high do
  10.        for j from j_low to j_high do
  11.            Xtemp := X[i];
  12.            Ytemp := Y[j];
  13.            Xc := Xtemp;
  14.            Yc := Ytemp;
  15.            k := 0;
  16.            while k < iter do
  17.                Xold := Xtemp;
  18.                Yold := Ytemp;
  19.                Xtemp := Xold^2-Yold^2+Xc;
  20.                Ytemp := 2*Xold*Yold+Yc;
  21.                if Xtemp^2+Ytemp^2 >= bailout then
  22.                    imageArray[i,j] := k;
  23.                    break;
  24.               end if;
  25.               k := k+1;
  26.            end do
  27.        end do;
  28.     end do;
  29. end proc:
  30. #If we're using Maple 13 or higher then multithread calculations, otherwise singlethread the calcualtions
  31. if parse(convert( kernelopts(version), string )[7..8]) >=13 then
  32. # This procedure recursively divides the complex plane into two strips, and creates a Task for each strip.  
  33. # These Tasks are sent to seperate cores for processesing (or enter a queue if the cores are busy)
  34. # Strips with 5 rows or less are sent to MandelLoop().
  35.    MandelTask := proc ( X, Y, imageArray, i_low, i_high, j_low, j_high, iter, bailout )
  36.        local i, j, i_mid;
  37.        if ( i_high - i_low > 5 ) then
  38.            i_mid := floor( (i_high-i_low)/2 ) + i_low;
  39.            Threads:-Task:-Continue( null,
  40.                Task=[MandelTask, X, Y, imageArray, i_low, i_mid, j_low, j_high, iter, bailout],
  41.                Task=[MandelTask, X, Y, imageArray, i_mid+1, i_high, j_low, j_high, iter, bailout ] );
  42.        else
  43.            MandelLoop( X, Y, imageArray, i_low, i_high, j_low, j_high, iter, bailout );
  44.        end if;
  45.    end proc:
  46. # Main entry function.  
  47. # numPoints - number of discretization points along real and imaginary axis on complex plane
  48. # iter - number of iterations for each discretized point on the complex plane
  49. # X1 and X2 - left and right point on the real axis
  50. # Y1 and Y2 - top and bottom point on imaginary axis
  51. # bailout - value of iterate above which a point is no longer considered to be in the Mandelbrot set
  52.    Mandelbrot := proc (numPoints::integer,iter::integer, X1::float, X2::float, Y1::float, Y2::float, bailout::float)
  53.        local X::Vector, Y::Vector, imageArray::Array, i::int, j::int:
  54.        X := Vector(numPoints, i->X1+(X2-X1)*(i-1)/(numPoints-1) , datatype = float[8]);
  55.        Y := Vector(numPoints, i->Y1+(Y2-Y1)*(i-1)/(numPoints-1) , datatype = float[8]);
  56.        imageArray := Array(1 .. numPoints, 1 .. numPoints, datatype = float[8]);
  57.        Threads:-Task:-Start( MandelTask, X, Y, imageArray, 1, numPoints, 1, numPoints, iter, bailout );
  58.        return imageArray;
  59.    end proc:

  60.    DocumentTools[SetProperty](threadedLabel,caption,cat("Multi-threading across ", kernelopts(numcpus), " CPUs"));
  61. else
  62.    Mandelbrot := proc ( numPoints::integer,iter::integer, X1::float, X2::float, Y1::float, Y2::float, bailout::float)
  63.        local X::Vector, Y::Vector, imageArray::Array:
  64.        X := Vector(numPoints, i->X1+(X2-X1)*(i-1)/(numPoints-1) , datatype = float[8]);
  65.        Y := Vector(numPoints, i->Y1+(Y2-Y1)*(i-1)/(numPoints-1) , datatype = float[8]);
  66.        imageArray := Array(1 .. numPoints, 1 .. numPoints, datatype = float[8]);
  67.        MandelLoop( X, Y, imageArray, 1, numPoints, 1, numPoints, iter, bailout );
  68.        return imageArray;
  69.    end proc:
  70.    DocumentTools[SetProperty](threadedLabel,caption,"Single-threaded mode");
  71. end if;
  72. #############################################
  73. #Set Default Values
  74. defaultNumPoints:=100:
  75. defaultIterations:=50:
  76. defaultxMandStart:=-2.0:
  77. defaultxMandEnd:=0.7:
  78. defaultyMandStart:=-1.35:
  79. defaultyMandEnd:=1.35:
  80. defaultBailout:=10.0:
  81. defaultNumPoints:=100:
  82. defaultIterations:=50:
  83. defaultSmoothing:=false:
  84. defaultGrayScaleColoring:=true:
  85. SetProperty(xMandStartLabel, caption, defaultxMandStart);
  86. SetProperty(xMandEndLabel, caption, defaultxMandEnd);
  87. SetProperty(yMandStartLabel , caption, defaultyMandStart);
  88. SetProperty(yMandEndLabel, caption, defaultyMandEnd);
  89. SetProperty(bailoutBox, value, defaultBailout);
  90. SetProperty(pointsBox, value, defaultNumPoints);
  91. SetProperty(iterationsBox, value, defaultIterations);
  92. SetProperty(smoothingCB,value,defaultSmoothing);
  93. SetProperty(grayScaleRB,value, defaultGrayScaleColoring);
  94. ############################################
  95. #############################################
  96. #Initialize the plot
  97. bailout:=defaultBailout:
  98. iterations:=defaultIterations:
  99. numPoints:=defaultNumPoints:
  100. smoothing:=defaultSmooting:
  101. if defaultGrayScaleColoring=true then coloring:=none: else coloring:=HUE: end if:
  102. xMandStart:=defaultxMandStart:
  103. xMandEnd:=defaultxMandEnd:
  104. yMandStart:=defaultyMandStart:
  105. yMandEnd:=defaultyMandEnd:
  106. points := Mandelbrot(numPoints, iterations, xMandStart, xMandEnd, yMandStart, yMandEnd, bailout);
  107. MandelbrotPlot:= plots[listdensityplot](points,style=patchnogrid,smooth=defaultSmoothing,colorstyle=coloring,axes=none);
  108. Do(%Plot1 = MandelbrotPlot);
  109. #############################################
  110. hasBeenDragged:=0:
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复 不支持

使用道具 举报

 楼主| 发表于 2009-9-8 14:10:40 | 显示全部楼层 来自 江苏无锡
硬件差不多,迭代次数和图形效果也差不多。、

Maple 的代码太长,太丑了。我只要三行代码。
回复 不支持

使用道具 举报

发表于 2009-9-8 14:22:49 | 显示全部楼层 来自 黑龙江哈尔滨
硬件差不多,迭代次数和图形效果也差不多。、

Maple 的代码太长,太丑了。我只要三行代码。
FreddyMusic 发表于 2009-9-8 14:10


你误会了。这是一个 用maple做的小小的二次开发,提供了 interactive设置、自动寻找多核(我的机器是双核的,所以上面显示的是2)。不是一个仅仅画出Mandelbrot 。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复 不支持

使用道具 举报

 楼主| 发表于 2009-9-8 14:24:40 | 显示全部楼层 来自 江苏无锡
你误会了。这是一个 用maple做的小小的二次开发,提供了 interactive设置、自动寻找多核(我的机器是双核的,所以上面显示的是2)。不是一个仅仅画出Mandelbrot 。
TBE_Legend 发表于 2009-9-8 14:22


这些 interactive设置 东西,Mathematica 中高级用户,5 分钟就能做出来。
回复 不支持

使用道具 举报

发表于 2009-9-8 14:34:43 | 显示全部楼层 来自 黑龙江哈尔滨
本帖最后由 TBE_Legend 于 2009-9-9 23:09 编辑
这些 interactive设置 东西,Mathematica 中高级用户,5 分钟就能做出来。
FreddyMusic 发表于 2009-9-8 14:24


http://www.wolfram.com/broadcast/screencasts/parallelcomputing/  一个简单的mmtc并行例子的视屏。

既然只需要5分钟,希望你能给大家做个来看看。附件是word文档,很小,里面提到了具体的做的一些interactive 操作,一看就明白。期待你的作品。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复 不支持

使用道具 举报

发表于 2009-9-8 16:09:33 | 显示全部楼层 来自 湖南怀化
哦,类似的分形程序我都有,自已写的,不并行,运算时间也不要多少啊!
回复 不支持

使用道具 举报

 楼主| 发表于 2009-9-8 17:08:38 | 显示全部楼层 来自 江苏无锡
本帖最后由 FreddyMusic 于 2009-9-8 17:11 编辑

我的作品多的很,根本不需再证明什么。
像这样的项目,对我而言,没有任何挑战性。
没有任何挑战性的项目,我一分钟也不会做。

你拿的东西都不是你自己原创的,所以你根本就不懂。
而我们 Mathematica 的东西都是我们自己原创,我们可以十分轻而易举的看懂你的东西,要想做成的一样的东西,那太容易了。
老实说,你用 Maple ,你把这些 Interative 的参数都解释一遍来给我听听。我听听你说得对不对。
回复 不支持

使用道具 举报

发表于 2009-9-9 10:18:52 | 显示全部楼层 来自 黑龙江大庆
曼德尔布洛特集合,难懂的东西!
回复 不支持

使用道具 举报

发表于 2009-9-9 11:37:08 | 显示全部楼层 来自 湖南怀化
到底Maple
Mathematica
Matlab
哪个了牛B?
回复 不支持

使用道具 举报

发表于 2009-9-9 15:42:16 | 显示全部楼层 来自 浙江宁波
10# minjiecow
Mathematica

不过maple有些地方好用,Matlab坚决抵制
回复 不支持

使用道具 举报

发表于 2009-9-9 15:55:21 | 显示全部楼层 来自 吉林长春
到底Maple
Mathematica
Matlab
哪个了牛B?
minjiecow 发表于 2009-9-9 11:37


自己试试才知道
回复 不支持

使用道具 举报

发表于 2010-11-29 00:16:29 | 显示全部楼层 来自 浙江嘉兴
2# TBE_Legend

要这么长呀,没怎么用过maple,感觉代码不好看
回复 不支持

使用道具 举报

发表于 2010-11-29 16:06:39 | 显示全部楼层 来自 上海徐汇区
回复看内容
回复 不支持

使用道具 举报

发表于 2010-11-29 17:29:44 | 显示全部楼层 来自 浙江嘉兴
看什么


14# yue586
回复 不支持

使用道具 举报

发表于 2010-11-29 17:31:57 | 显示全部楼层 来自 浙江嘉兴
看看

14# yue586
回复 不支持

使用道具 举报

发表于 2010-11-29 17:34:26 | 显示全部楼层 来自 浙江嘉兴
看看

14# yue586
回复 不支持

使用道具 举报

发表于 2010-11-29 17:38:39 | 显示全部楼层 来自 上海徐汇区
隐藏的内容。
回复 不支持

使用道具 举报

发表于 2011-3-25 10:38:25 | 显示全部楼层 来自 山西太原
看看是什么东西了。。。
回复 不支持

使用道具 举报

发表于 2011-5-21 01:56:31 | 显示全部楼层 来自 新疆
看看看看是什么东西了。。。
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-3-29 07:47 , Processed in 0.064452 second(s), 14 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表