mathe 发表于 2008-2-14 12:38:05

got,没有调试功能简单的错误都找不出来。
现在程序在使用
SQRTSMALLPRIMES=200
LIMIT_SIZE=10,000,000时就可以在比较合理的时间内找出10进制100位左右结果了:
**** Hidden Message *****
程序运行中部分结果,看来缓冲区选择太大了,结果还在继续产生中。
其中每个输出数字n, {n-4,n-2,n+2,n+4}才是素数。
Call HugeCalc V8.0.0.0

Filter cost 34380ms
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 9829 4389 AFF9
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 9829 9BF9 A22F
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 9829 B44A 52BB
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 9829 C541 B9B5
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 9829 D11B A6D3
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982A 0FAA EE63
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982A 1CA3 EBE7
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982A 31BC BEB9
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982A 4878 8B29
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982A 4BC0 3165
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982A 518D 168F

mathe 发表于 2008-2-14 12:43:43

呵呵第一次使用HugeCalc编程,查看了一下你的文档,然后直接修改你的例子产生的代码。
程序已经运行完了。总共287410s(呵呵,正好5分钟左右),算出14组数。
Call HugeCalc V8.0.0.0

Filter cost 34380ms
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 9829 4389 AFF9
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 9829 9BF9 A22F
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 9829 B44A 52BB
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 9829 C541 B9B5
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 9829 D11B A6D3
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982A 0FAA EE63
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982A 1CA3 EBE7
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982A 31BC BEB9
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982A 4878 8B29
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982A 4BC0 3165
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982A 518D 168F
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982A A17A 99DD
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982A EE98 6321
Found n-4,n-2,n+2,n+4 where n is 0x 4720 15C7 CFAB 47C6 7498 B6F7 5DE7 8537 9C19
336C E833 5AA8 DF88 56E8 2CBC 3D72 ED7B 005A 982B 5866 F3DF
Total took 287410 ms
Press any key to continue . . .

mathe 发表于 2008-2-14 12:45:22

不过不知道为什么,只使用一个CPU,是不是选项没有打开?

mathe 发表于 2008-2-14 12:54:14

上面忘了加前面部分筛选花的时间了,正好超过5分钟。
我又试着将SQRTSMALLPRIMES改成400(加大筛选范围),重新算一次快多了。
Call HugeCalc V8.0.0.0

Filter cost 42145ms
Found n-4,n-2,n+2,n+4 where n is 0x 75A9 4010 2C19 E028 A536 41BE 101B 31C3 4208
318A F342 C8B1 FADF 2FFC 597A 4CEC 1B1E 891C 44E7 2DB4 1105
Found n-4,n-2,n+2,n+4 where n is 0x 75A9 4010 2C19 E028 A536 41BE 101B 31C3 4208
318A F342 C8B1 FADF 2FFC 597A 4CEC 1B1E 891C 44E7 4684 5DCF
Found n-4,n-2,n+2,n+4 where n is 0x 75A9 4010 2C19 E028 A536 41BE 101B 31C3 4208
318A F342 C8B1 FADF 2FFC 597A 4CEC 1B1E 891C 44E7 4A1E 6C41
Found n-4,n-2,n+2,n+4 where n is 0x 75A9 4010 2C19 E028 A536 41BE 101B 31C3 4208
318A F342 C8B1 FADF 2FFC 597A 4CEC 1B1E 891C 44E7 68D0 A1D1
Found n-4,n-2,n+2,n+4 where n is 0x 75A9 4010 2C19 E028 A536 41BE 101B 31C3 4208
318A F342 C8B1 FADF 2FFC 597A 4CEC 1B1E 891C 44E7 6D24 3B0D
Found n-4,n-2,n+2,n+4 where n is 0x 75A9 4010 2C19 E028 A536 41BE 101B 31C3 4208
318A F342 C8B1 FADF 2FFC 597A 4CEC 1B1E 891C 44E7 9D9D F0CB
Found n-4,n-2,n+2,n+4 where n is 0x 75A9 4010 2C19 E028 A536 41BE 101B 31C3 4208
318A F342 C8B1 FADF 2FFC 597A 4CEC 1B1E 891C 44E8 3DE3 F8EB
Found n-4,n-2,n+2,n+4 where n is 0x 75A9 4010 2C19 E028 A536 41BE 101B 31C3 4208
318A F342 C8B1 FADF 2FFC 597A 4CEC 1B1E 891C 44E8 57F4 7B6B
Found n-4,n-2,n+2,n+4 where n is 0x 75A9 4010 2C19 E028 A536 41BE 101B 31C3 4208
318A F342 C8B1 FADF 2FFC 597A 4CEC 1B1E 891C 44E8 96B0 91E1
Found n-4,n-2,n+2,n+4 where n is 0x 75A9 4010 2C19 E028 A536 41BE 101B 31C3 4208
318A F342 C8B1 FADF 2FFC 597A 4CEC 1B1E 891C 44E9 03EC AE75
Found n-4,n-2,n+2,n+4 where n is 0x 75A9 4010 2C19 E028 A536 41BE 101B 31C3 4208
318A F342 C8B1 FADF 2FFC 597A 4CEC 1B1E 891C 44E9 0795 2543
Total took 177493 ms
Press any key to continue . . .

mathe 发表于 2008-2-14 13:01:18

呵呵,有运行了一次,结果运气不好,遇上无解了。
本来想继续加大SQRTSMALLPRIMES现在看来不适合,因为遇上这种情况,如果真要找到一下个解,只能重新从下一块区域开始筛选

mathe 发表于 2008-2-14 13:08:07

实际计算表明j继续增加SQRTSMALLPRIMES对速度影响不大

gxqcn 发表于 2008-2-14 13:19:29

原帖由 mathe 于 2008-2-14 12:45 发表 http://bbs.emath.ac.cn/images/common/back.gif
不过不知道为什么,只使用一个CPU,是不是选项没有打开?

不是的。多核仅被应用于FNT算法中,即只有内部大数乘法达到一定规模时才会被用到。
其它算法,任务不易切分,且不便线程池的控制,所以就没用多线程。

mathe 发表于 2008-2-14 13:36:25

原帖由 gxqcn 于 2008-2-14 13:19 发表 http://bbs.emath.ac.cn/images/common/back.gif


不是的。多核仅被应用于FNT算法中,即只有内部大数乘法达到一定规模时才会被用到。
其它算法,任务不易切分,且不便线程池的控制,所以就没用多线程。
同意,是我考虑不周全。看来对于这道题目,可以简单在后面寻找素数的循环上加上openmp的标记,可以通过并行提高计算速度:)

上载一个预编译后的代码,不过运行需要能够找到郭老大的HugeCalc.dll(输出为十六进制数)

gxqcn 发表于 2008-2-14 13:57:19

备注:本帖于 2008-02-15 19:30 最后修正!

参考 mathe 的代码,略作了些修改(省却了小素数的搜索过程):// HugeCalcDemo.cpp : Defines the entry point for the console application.
//

// Project -> Setting -> C/C++ -> Code Generation --> Use run-time library:
//Win32 Debug:    Debug Multithreaded DLL
//Win32 Release:Multithreaded DLL

// 以下代码源自 mathe 的,略有修改

#include <time.h>
#include <iostream>
using namespace std;
#include "../../../HugeCalc_API/CppAPI/Include/HugeCalc.h"// 公共接口
#include "../../../HugeCalc_API/CppAPI/Include/HugeInt.h"   // 10进制系统
#include "../../../HugeCalc_API/CppAPI/Include/HugeIntX.h"// 16进制系统

#pragma message( "automatic link to ../../../HugeCalc_API/CppAPI/Lib/HugeCalc.lib" )
#pragma comment( lib, "../../../HugeCalc_API/CppAPI/Lib/HugeCalc.lib" )

#if 1
    #define _Test_HI
    #define integer CHugeInt
#else
    #define _Test_HX
    #define integer CHugeIntX
#endif

#define SMALLPRIMES 0x1000000

#define LIMIT_SIZE 10000000UL
#define RANGE (LIMIT_SIZE<<5)
UINT32 mask;
#define SET_MASK(x)(mask[(x)>>5] |= 1UL<<((x)&31))
#define IS_SET(k,i)(mask&(1UL<<(i)))

int main(int argc, char* argv[])
{
    cout << "Call " << HugeCalc::GetVer() << endl << endl;

    if ( HC_LICENSE_NONE == HugeCalc::GetLicenseLevel())
    {
      cout << endl << "警告:您未通过 HugeCalc.dll 的许可认证!" \
            << endl << endl << "解决方案可选下列方案之一:" \
            << endl << "    一、请将本程序移动到“/CopyrightByGuoXianqiang/[../]”目录下运行;" \
            << endl << "    二、或请在 HugeCalc.chm 中进行注册(一劳永逸)。" \
            << endl << endl;
      system( "pause" );
      return (-1);
    }

    // 初始化
    HugeCalc::EnableTimer( TRUE );
    HugeCalc::ResetTimer();

    // 下面这条语句可以不必调用,HugeCalc 初始化时内部已执行该过程
    // HugeCalc::SeedRandom(time(NULL));

    integer hugeStart;
#ifdef _Test_HI
#if 0
    hugeStart.Random(100);
#else
    ( hugeStart = 1 ).DecLShift( 100 );
#endif
#else
    hugeStart.Random(335);
#endif

    CONST UINT32 spcount = HugeCalc::GetPrimePi( SMALLPRIMES ) - 3;//skip prime 2,3,5
    UINT32 * sptable = new UINT32[ spcount ];
    HugeCalc::GetPrimeList( sptable, spcount, 7, SMALLPRIMES );

    UINT32 i,k,m,s,p,v,h;
    CONST UINT32 filter_list[] = { 0, 2, 6, 8 };

    memset( mask, 0, sizeof(mask) );

    m = hugeStart%30;
    hugeStart += (11>=m) ? (11-m) : (41-m); //After the normalization, hugeStart%30==11

    for(k=0;k<spcount;k++){
      p = sptable;
      m = hugeStart%p;
      v = HugeCalc::InvertMod(30,p);
      for(i=0;i<sizeof(filter_list)/sizeof(filter_list);i++){
            s = filter_list+m;
            s = ( p >= s ) ? ( p - s ) : ( p*2 - s );
#if ( SMALLPRIMES <= 0xFFFF )
            ( s *= v ) %= p; //hugeStart+s*30+filter_list==0 (mod p)
#else
            s = (UINT32)( UInt32x32To64( s, v ) % p ); // 同上
#endif
            for(h=s;h<RANGE;h+=p){
                SET_MASK(h);//Filter hugeStart+h*30
            }
      }
    }

    delete []sptable;

    cout << "Filter cost "<< HugeCalc::GetTimer( TIMER_UNIT_ms ) << "ms" <<endl;
    HugeCalc::ResetTimer();


    UINT32 tcount=0, gcount=0;

    s = 0;
    for(k=0;k<LIMIT_SIZE;k++){
      for(i=0;i<32;i++){
            if(!IS_SET(k,i)){//hugeStart+i*30 may be a candidate
                ++tcount;
                hugeStart += s;
                if( (s =0, hugeStart.TestPrimality(1)!=COMPOSITE ) &&
                  (s-=2, (hugeStart+=2).TestPrimality(2)!=COMPOSITE) &&
                  (s-=4, (hugeStart+=4).TestPrimality(3)!=COMPOSITE) &&
                  (s-=2, (hugeStart+=2).IsPrime()) &&
                  (s+=2, (hugeStart-=2).IsPrime()) &&
                  (s+=4, (hugeStart-=4).IsPrime()) &&
                  (s+=2, (hugeStart-=2).IsPrime())){
                  //Output the candidate;
                  cout<< HugeCalc::GetTimerStr(FT_HHMMSS_ms) << "No." << ++gcount \
                        << "Found (n,n+2,n+6,n+8) where n is "
#ifdef _Test_HI
                        << hugeStart.GetStr( FS_NORMAL ) <<endl;
#else                   // 下面语句可将16进制大数直接以10进制数格式输出
                        << hugeStart.GetStrRadix( 10, NULL, FS_NORMAL ) <<endl;
#endif
               }
            }

            s += 30;
      }
    }

    cout << "Total test "<<tcount<<" Numbers, get "<<gcount<<" numbers"<<endl;

    system( "pause" );
    return 0;
}大家可以将它复制覆盖原 \HugeCalc\testDLL\src\ANSI_C++\ansi_c++.cpp,再编译即可。

在我的蹩脚机器上运行结果如下:Call HugeCalc V8.0.0.0

Filter cost 68254ms
00:00:07.194No.1Found (n,n+2,n+6,n+8) where n is 100000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000001053594241
00:00:07.370No.2Found (n,n+2,n+6,n+8) where n is 100000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000001069468231
00:00:16.808No.3Found (n,n+2,n+6,n+8) where n is 100000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000002439435571
00:00:23.487No.4Found (n,n+2,n+6,n+8) where n is 100000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000003413496841
00:00:25.334No.5Found (n,n+2,n+6,n+8) where n is 100000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000003681511741
00:00:31.152No.6Found (n,n+2,n+6,n+8) where n is 100000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000004552552081
00:00:37.123No.7Found (n,n+2,n+6,n+8) where n is 100000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000005435223751
00:00:38.937No.8Found (n,n+2,n+6,n+8) where n is 100000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000005692544401
00:00:44.441No.9Found (n,n+2,n+6,n+8) where n is 100000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000006496820491
00:00:55.114No.10Found (n,n+2,n+6,n+8) where n is 10000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000008049785491
00:00:57.931No.11Found (n,n+2,n+6,n+8) where n is 10000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000008455204681
00:00:58.478No.12Found (n,n+2,n+6,n+8) where n is 10000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000008532272461
00:01:02.213No.13Found (n,n+2,n+6,n+8) where n is 10000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000009077484631
Total test 51248 Numbers, get 13 numbers
请按任意键继续. . .速度快得惊人!

截屏如下:

mathe 发表于 2008-2-14 14:02:43

十进制计算我觉得应该慢一些,这也是为什么我要选择16进制计算。可以计算完了将计算结果再转化为10进制数。
页: 1 [2] 3 4 5 6 7
查看完整版本: 估计下找到10^100以上的一个四生素数的工作量