16阶以下子环搜索:多核并行计算版本
Posted 华仔Ivan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了16阶以下子环搜索:多核并行计算版本相关的知识,希望对你有一定的参考价值。
D:\\MathTool\\gaptool>IRingMT 1
CreateThread 0 OK,threadID=11412,h_thread=284
CreateThread 1 OK,threadID=11576,h_thread=320
CreateThread 2 OK,threadID=6816,h_thread=316
g_i=1
fsubring cnt1=1:R4_9->i=1,j=2
fsubring cnt1=2:R4_7->i=1,j=4
fsubring cnt1=3:R16_373->i=1,j=6
fsubring cnt1=4:R8_37->i=1,j=14
cnt=262144
g_i=1
fsubring3 cnt1=1:R4_3->i=1,j=2,k=3
fsubring3 cnt1=2:R16_101->i=1,j=2,k=4
fsubring cnt1=5:R4_8->i=1,j=16
cnt=262144
g_i=1
fsubring2 cnt1=1:R4_3->i=1,j=2
fsubring3 cnt1=3:R8_20->i=1,j=2,k=8
fsubring2 cnt1=2:R16_101->i=1,j=4
fsubring cnt1=6:R16_370->i=1,j=18
fsubring2 cnt1=3:R8_20->i=1,j=8
fsubring cnt1=7:R16_300->i=1,j=20
fsubring3 cnt1=4:R16_102->i=1,j=2,k=64
fsubring cnt1=8:R8_44->i=1,j=50
fsubring cnt1=9:R8_36->i=1,j=60
fsubring2 cnt1=4:R16_102->i=1,j=64
fsubring cnt1=10:R16_358->i=1,j=62
fsubring cnt1=11:R4_10->i=1,j=64
fsubring3 cnt1=5:R8_15->i=1,j=2,k=128
fsubring cnt1=12:R8_48->i=1,j=66
fsubring3 cnt1=6:R16_201->i=1,j=2,k=136
fsubring2 cnt1=5:R8_15->i=1,j=128
fsubring cnt1=13:R8_49->i=1,j=68
fsubring2 cnt1=6:R16_201->i=1,j=136
fsubring cnt1=14:R16_371->i=1,j=78
fsubring3 cnt1=7:R16_104->i=1,j=2,k=256
fsubring2 cnt1=7:R16_104->i=1,j=256
fsubring cnt1=15:R16_295->i=1,j=124
fsubring cnt1=16:R16_384->i=1,j=130
fsubring2 cnt1=8:R8_13->i=1,j=512
fsubring2 cnt1=9:R16_203->i=1,j=520
fsubring3 cnt1=8:R8_13->i=1,j=2,k=512
fsubring3 cnt1=9:R16_203->i=1,j=2,k=520
fsubring cnt1=17:R4_6->i=1,j=192
fsubring cnt1=18:R8_35->i=1,j=194
fsubring cnt1=19:R16_375->i=1,j=196
fsubring2 cnt1=10:R16_204->i=1,j=640
fsubring3 cnt1=10:R16_204->i=1,j=2,k=640
fsubring cnt1=20:R8_29->i=1,j=204
fsubring2 cnt1=11:R16_112->i=1,j=1024
fsubring3 cnt1=11:R16_112->i=1,j=2,k=1024
fsubring cnt1=21:R16_336->i=1,j=206
fsubring2 cnt1=12:R16_113->i=1,j=1536
fsubring3 cnt1=12:R16_113->i=1,j=2,k=1536
fsubring cnt1=22:R8_34->i=1,j=240
fsubring cnt1=23:R16_352->i=1,j=242
fsubring cnt1=24:R16_335->i=1,j=252
fsubring cnt1=25:R8_28->i=3,j=4
fsubring cnt1=26:R4_4->i=3,j=12
fsubring cnt1=27:R16_363->i=3,j=28
fsubring cnt1=28:R16_374->i=3,j=69
fsubring cnt1=29:R8_45->i=3,j=77
#include<set>
#include"DecompositionRing.h"
#include"Rn.h"
#include"M2r.h"
#include"Mnr.h"
#include"PolynomialRing.h"
#include <ctime>
#include <fstream>
#include <windows.h>
int g_i=0;
void fsubring(M2r *r,int n)
map<pair<int,int>,pair<int,int>> M;
printf("g_i=%d\\n",g_i);
for(int i=g_i;i<r->size()-1;i++)
for(int j=i+1;j<r->size();j++)
//int j=i+1;
vector<int> v;
v.push_back(i);
v.push_back(j);
Subring S1i;
bool bn=S1i.init(r,v,16);
if(!bn)
continue;
//Subring S1i(r,v);
int ni=S1i.size();
if(ni>16)
continue;
int ID=IdRing(&S1i);
int cnt=M.size();
M.insert(make_pair(make_pair(ni,ID),make_pair(i,j)));
int cnt1=M.size();
if(cnt1>cnt)
printf("%s cnt1=%d:R%d_%d->i=%d,j=%d\\n",__FUNCTION__,cnt1,ni,ID,i,j);
if(ni==n && ID==-1||(ID==230||ID==232||ID==236||ID==241||ID==244||ID==246||ID==337)||(ni==8 && (ID==6||ID==9||ID==12||ID==18||ID==39)))
string str=M2r::MStr(r->m_Set[i]);
printf("%d->%s=>",i,str.c_str());
string strj=M2r::MStr(r->m_Set[j]);
printf("%d->%s=>",j,strj.c_str());
string strR=calcRingInvariant(&S1i);
printf("R%d_%d:N0n0bAbOn1n2n4n5n6n7n8S1N2=%s\\n",ni,ID,strR.c_str());
//S1i.printTable();
//break;
void fsubring2(Mnr *r,int n)
#define PRINT_LOG 1
bool bFind=false;
#if PRINT_LOG
char sz[100]="0";
sprintf(sz,"R%d_%d.txt",r->size(),time(NULL));
ofstream fout(sz);
#endif
string strCmd="del ";
strCmd+=sz;
map<pair<int,int>,pair<int,int>> M;
printf("g_i=%d\\n",g_i);
for(int i=g_i;i<r->size()-1;i++)
for(int j=i+1;j<r->size();j++)
//int j=i+1;
vector<int> v;
v.push_back(i);
v.push_back(j);
Subring S1i;
bool bn=S1i.init(r,v,16);
if(!bn)
continue;
//Subring S1i(r,v);
int ni=S1i.size();
if(ni>16)
continue;
int ID=IdRing(&S1i);
int cnt=M.size();
M.insert(make_pair(make_pair(ni,ID),make_pair(i,j)));
int cnt1=M.size();
if(cnt1>cnt)
printf("%s cnt1=%d:R%d_%d->i=%d,j=%d\\n",__FUNCTION__,cnt1,ni,ID,i,j);
if(ni==n && ID==-1||(ID==230||ID==232||ID==236||ID==241||ID==244||ID==246||ID==337)||(ni==8 && (ID==6||ID==9||ID==12||ID==18||ID==39)))
string str=Mnr::MStr(r->m_Set[i]);
printf("%d->%s=>",i,str.c_str());
string strj=Mnr::MStr(r->m_Set[j]);
printf("%d->%s=>",j,strj.c_str());
string strR=calcRingInvariant(&S1i);
printf("R%d_%d:N0n0bAbOn1n2n4n5n6n7n8S1N2=%s\\n",ni,ID,strR.c_str());
//S1i.printTable();
#if PRINT_LOG
fout<<i<<"->"<<str<<","<<j<<"->"<<strj<<"=>";
fout<<__FUNCTION__<<"R"<<ni<<"_"<<ID<<":N0n0bAbOn1n2n4n5n6n7n8S1N2="<<strR<<endl;
bFind=true;
#endif
//break;
#if PRINT_LOG
fout.close();
if(!bFind)
system(strCmd.c_str());
else
printf("子环表示已输出到文件%s\\n",sz);
#endif
void fsubring3(Mnr *r,int n)
#define PRINT_LOG 1
bool bFind=false;
#if PRINT_LOG
char sz[100]="0";
sprintf(sz,"R%d_%d.txt",r->size(),time(NULL));
ofstream fout(sz);
#endif
string strCmd="del ";
strCmd+=sz;
map<pair<int,int>,pair<int,int>> M;
printf("g_i=%d\\n",g_i);
for(int i=g_i;i<r->size()-2;i++)
for(int j=i+1;j<r->size()-1;j++)
for(int k=j+1;k<r->size();k++)
//int j=i+1;
vector<int> v;
v.push_back(i);
v.push_back(j);
v.push_back(k);
Subring S1i;
bool bn=S1i.init(r,v,16);
if(!bn)
continue;
//Subring S1i(r,v);
int ni=S1i.size();
if(ni>16)
continue;
int ID=IdRing(&S1i);
int cnt=M.size();
M.insert(make_pair(make_pair(ni,ID),make_pair(i,j)));
int cnt1=M.size();
if(cnt1>cnt)
printf("%s cnt1=%d:R%d_%d->i=%d,j=%d,k=%d\\n",__FUNCTION__,cnt1,ni,ID,i,j,k);
if(ni==n && ID==-1||(ID==230||ID==232||ID==236||ID==241||ID==244||ID==246||ID==337)||(ni==8 && (ID==6||ID==9||ID==12||ID==18||ID==39)))
string str=Mnr::MStr(r->m_Set[i]);
printf("%d->%s=>",i,str.c_str());
string strj=Mnr::MStr(r->m_Set[j]);
printf("%d->%s=>",j,strj.c_str());
string strk=Mnr::MStr(r->m_Set[k]);
printf("%d->%s=>",k,strk.c_str());
string strR=calcRingInvariant(&S1i);
printf("R%d_%d:N0n0bAbOn1n2n4n5n6n7n8S1N2=%s\\n",ni,ID,strR.c_str());
//S1i.printTable();
#if PRINT_LOG
fout<<i<<"->"<<str<<","<<j<<"->"<<strj<<","<<k<<"->"<<strk<<"=>";
fout<<__FUNCTION__<<"R"<<ni<<"_"<<ID<<":N0n0bAbOn1n2n4n5n6n7n8S1N2="<<strR<<endl;
bFind=true;
#endif
//break;
#if PRINT_LOG
fout.close();
if(!bFind)
system(strCmd.c_str());
else
printf("子环表示已输出到文件%s\\n",sz);
#endif
DWORD WINAPI M3Z4ijk( void* lpParameter )
ZmodnZ r(1,4);
Mnr m2r(&r,3);
fsubring3(&m2r,16);
ExitThread(0);
return 0;
;
DWORD WINAPI M3Z4ij( void* lpParameter )
ZmodnZ r(1,4);
Mnr m2r(&r,3);
fsubring2(&m2r,16);
ExitThread(0);
return 0;
;
DWORD WINAPI M2I4ij( void* lpParameter )
M2r r;
r.initI(2);
#if 0
Mnr m2r(&r,2);
fsubring2(&m2r,16);
#else
M2r m2r(&r);
fsubring(&m2r,16);
#endif
ExitThread(0);
return 0;
;
int main(int argc, char* argv[])
if(argc>1)
g_i=atoi(argv[1]);
PTHREAD_START_ROUTINE tfun[]=M3Z4ijk,M3Z4ij,M2I4ij;
unsigned long threadID[]=0,0,0;
HANDLE h_thread[]=0,0,0;//句柄数组
DWORD maskArr[]=0x02,0x04,0x08;//i7-6500U CPU,绑定线程到指定的CPU核心(CPU 1~3)
int cnt=sizeof(tfun)/sizeof(tfun[0]);
for(int i=0;i<cnt;i++)
h_thread[i]=CreateThread( NULL, 0, tfun[i], NULL, 0, &threadID[i] );
if(NULL != h_thread[i])
printf("CreateThread %d OK,threadID=%d,h_thread=%d\\n",i,threadID[i],h_thread[i]);
SetThreadAffinityMask(h_thread[i],maskArr[i]);
WaitForMultipleObjects(cnt,h_thread,TRUE,INFINITE);
printf("main thread\\n");
for(int i=0;i<cnt;i++)
CloseHandle(h_thread[i]);
#ifdef _DEBUG
system("pause");
#endif
return 0;
以上是关于16阶以下子环搜索:多核并行计算版本的主要内容,如果未能解决你的问题,请参考以下文章