我一直在使用 pari/gp(配置显示在下面的输出中)来计算大型密集矩阵的行列式。例如,我在 Linux 笔记本电脑上使用四核 i7、16GB RAM、32GB 交换空间来计算 1700x1700 的矩阵,精度略低于 3000 位。这需要大约 17 个小时,使用所有八个线程,100% 的时间,但只有一点 RAM。然后,它在另外六个小时内执行行列式,一个核心使用 100% 的行列式,而 kswapd 使用另一个核心,100% 的时间(并且似乎能够跟上并使用所有交换空间)。行列式在 pari/gp 中没有并行化(据我所知,除了 kswapd 和 gp 实例使用单独的内核)。这是一个具体示例(不使用并行代码),计算随机(浮点),1000 位精度,
我知道这不是 matlab,但在我看来,这是一种更好的方法。
=========================== cut here
default(nbthreads,2); \\this example sets up two but uses only one thread.
default(threadsize, 500 000 000);
default(parisize, 1 800 000 000); \\ make sure there is enough RAM allocated
initrand()=
{
cmd = "date +\"%s\""; \\ a linux command to get the time
seed = eval(externstr(cmd)[1]); \\ evaluate the external command
setrand(seed); \\ set the random seed in pari/gp
print ("Random Number Seed = ", seed); \\ this is what it is
return(seed); \\ don't really use this value any more
}
{
default(realprecision, 1000); \\ accurate to 1000 digits of precision
initrand(); \\ pari/gp seems to need a different seed every time
M = matrix(300,300,i,j,random(1.0)); \\ some small random matrix
printf ("%10.7f\n", M[1,1]); \\ print the first matrix element
detM = matdet(M); \\ calculate the determinant
print (detM); \\ print the result of the determinant
quit();
}
========================================= cut here
这是输出,在这台使用了八年的笔记本电脑(双核,2GB 内存,不是快速的 ThinkPad)上花了一分钟左右的时间。
GP/PARI CALCULATOR Version 2.7.3 (released)
amd64 running linux (x86-64/GMP-6.0.0 kernel) 64-bit version
compiled: Mar 20 2015, gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
threading engine: pthread
(readline v6.3 enabled, extended help enabled)
Copyright (C) 2000-2015 The PARI Group
PARI/GP is free software, covered by the GNU General Public License, and comes WITHOUT ANY WARRANTY WHATSOEVER.
Type ? for help, \q to quit.
Type ?12 for how to get moral (and possibly technical) support.
parisize = 8000000, primelimit = 500000
*** Warning: new stack size = 1800000000 (1716.614 Mbytes).
Random Number Seed = 1442728837
0.1458753
-34107869659292788498041296259204073212856192996487539539650250444333175626443030051167504275069295850290060165906721403518710248631573270877318755.16606345550957294257524953917496320048631959234301670865079024142295995123023952749154306602088800645390346232704746782547685913565513791084278569243333238872632785910522536912572116356801097060790810716175151647494785903522152367435398630683566431045727806979724702836066399155098909578586486867501579225868835988817237083450602429253202805656099228929576538193846647490928888795367874033893827126923874835063405546089363260880884557106553366031910609740691344849673406340416580053579023527252144631532815837507760281113528779522639792441184911588021824240226126036961995649658869925314847019638680109421905217088024624421267647700950443089481208575217193882687232501653341331383260930401032570115570957029275695235564734394098177016567882258012726222978777317463869837697774536180341558237759707887932943904115121644125119662351721076540409972736105729
Goodbye!
当然,在这种情况下,“-341......05729”是浮点结果。我没有玩过整数矩阵元素,但我确信它同样好,如果不是更好的话。