void SoundStream::loop(double volume) { int numQueued = 0; AL(alGetSourcei(source.getId(), AL_BUFFERS_QUEUED, &numQueued)); if (numQueued == 0) { /*fill and queue initial buffers*/ vector<char> data = readSoundData(*file, streamingBufferSize); AL(alBufferData(buffers[0], (info->channels > 1) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, data.data(), data.size(), info->rate)); data = readSoundData(*file, streamingBufferSize); AL(alBufferData(buffers[1], (info->channels > 1) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, data.data(), data.size(), info->rate)); AL(alSourceQueueBuffers(source.getId(), 2, buffers)); AL(alSourcef(source.getId(), AL_GAIN, volume)); AL(alSourcePlay(source.getId())); startedPlaying = true; //CHECK(isPlaying()); fails if I unplug/plug the speaker cable...? } else { /*refill processed buffers*/ int numProcessed = 0; AL(alGetSourcei(source.getId(), AL_BUFFERS_PROCESSED, &numProcessed)); while (numProcessed--) { vector<char> data = readSoundData(*file, streamingBufferSize); if (data.size() == 0) break; else { ALuint buffer = 0; AL(alSourceUnqueueBuffers(source.getId(), 1, &buffer)); AL(alBufferData(buffer, (info->channels > 1) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, data.data(), data.size(), info->rate)); AL(alSourceQueueBuffers(source.getId(), 1, &buffer)); } } } sleep_for(milliseconds(10)); }
void create(NODEL **head,NODET *root) { if(root==NULL) AL(head,"*"); else { AL(head, root->data); create(head,root->left); create(head,root->right); } }
void createList(NodeT *root, NodeL **head) { if(root==NULL) AL(head,"*"); else { AL(head, root->data); createList(root->left,head); createList(root->right,head); } }
void AudioDevice::play(const SoundBuffer& sound, double volume, double pitch) { RecursiveLock lock(mutex); if (auto source = getFreeSource()) { ALint state = 0; AL(alGetSourcei(*source, AL_SOURCE_STATE, &state)); CHECK(state == AL_INITIAL) << state; AL(alSourcei(*source, AL_BUFFER, sound.getBufferId())); AL(alSourcef(*source, AL_PITCH, pitch)); AL(alSourcef(*source, AL_GAIN, volume)); AL(alSourcePlay(*source)); } }
SoundBuffer::SoundBuffer(const FilePath& path) { OggVorbis_File file; CHECK(ov_fopen(path.getPath(), &file) == 0) << "Error opening audio file: " << path; vorbis_info* info = ov_info(&file, -1); ov_raw_seek(&file, 0); vector<char> buffer = readSoundData(file); OpenalId id; AL(alGenBuffers(1, &id)); AL(alBufferData(id, (info->channels > 1) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, buffer.data(), buffer.size(), info->rate)); bufferId = id; ov_clear(&file); }
void GEMENI_charsent() { unsigned long r = s->log[s->lc]; if (UCA0IFG & UCTXIFG) { s->nch++; switch (s->nch) { case 1: UCA0TXBUF = SL(r) << 5 |TL(r)<<4|KL(r)<<3|PL(r)<<2|WL(r)<<1|HL(r); break; case 2: UCA0TXBUF = RL(r)<<6 | AL(r)<<5 | OL(r)<<4 | STAR(r)<<3; break; case 3: UCA0TXBUF = ER(r)<<3 | UR(r)<<2 | FR(r)<<1 | RR(r); break; case 4: UCA0TXBUF = PR(r)<<6 | BR(r)<<5 | LR(r)<<4 | GR(r)<<3 | TR(r)<<2 | SR(r)<<1 | DRS(r); break; case 5: UCA0TXBUF = POUND(r)<<1 | ZRS(r); break; default: s->lc++; if (s->lc != s->nc-1) { s->nch = 0; UCA0TXBUF = 1 << 7; // first packet, no fn or '#' } else { s->flags &= ~CSEND; } } } }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int M,N,NN,K; double *a_arr,*b_arr; if ( nrhs != 2 ) mexErrMsgTxt("Wrong number of input arguments!"); else if ( nlhs > 1 ) mexErrMsgTxt("Too many output arguments!"); M = mxGetM(A); N = mxGetN(A); NN = mxGetM(b); K = mxGetN(b); a_arr = mxGetPr(A); b_arr = mxGetPr(b); if (M!=NN) mexErrMsgTxt("Wrong input!"); Matrix AL(M,N,a_arr); Matrix br(NN,K,b_arr); COPT::LU<Matrix> lu(AL); Matrix x=lu.solve(br); plhs[0] = mxCreateDoubleMatrix(N,K,mxREAL); double *l = mxGetPr(plhs[0]); for ( int i = 0 ; i < x.size() ; ++ i ) { l[i] = x.dataPtr()[i]; } return; }
bool SoundStream::isPlaying() const { if (!startedPlaying) return true; ALint state = 0; AL(alGetSourcei(source.getId(), AL_SOURCE_STATE, &state)); return state == AL_PLAYING; }
inline void SyrkLN ( T alpha, const DistMatrix<T>& A, T beta, DistMatrix<T>& C, bool conjugate=false ) { #ifndef RELEASE PushCallStack("internal::SyrkLN"); if( A.Grid() != C.Grid() ) throw std::logic_error ("A and C must be distributed over the same grid"); if( A.Height() != C.Height() || A.Height() != C.Width() ) { std::ostringstream msg; msg << "Nonconformal SyrkLN:\n" << " A ~ " << A.Height() << " x " << A.Width() << "\n" << " C ~ " << C.Height() << " x " << C.Width() << "\n"; throw std::logic_error( msg.str().c_str() ); } #endif const Grid& g = A.Grid(); // Matrix views DistMatrix<T> AL(g), AR(g), A0(g), A1(g), A2(g); // Temporary distributions DistMatrix<T,MC, STAR> A1_MC_STAR(g); DistMatrix<T,VR, STAR> A1_VR_STAR(g); DistMatrix<T,STAR,MR > A1Trans_STAR_MR(g); A1_MC_STAR.AlignWith( C ); A1_VR_STAR.AlignWith( C ); A1Trans_STAR_MR.AlignWith( C ); // Start the algorithm ScaleTrapezoid( beta, LEFT, LOWER, 0, C ); LockedPartitionRight( A, AL, AR, 0 ); while( AR.Width() > 0 ) { LockedRepartitionRight ( AL, /**/ AR, A0, /**/ A1, A2 ); //--------------------------------------------------------------------// A1_VR_STAR = A1_MC_STAR = A1; A1Trans_STAR_MR.TransposeFrom( A1_VR_STAR, conjugate ); LocalTrrk( LOWER, alpha, A1_MC_STAR, A1Trans_STAR_MR, T(1), C ); //--------------------------------------------------------------------// SlideLockedPartitionRight ( AL, /**/ AR, A0, A1, /**/ A2 ); } #ifndef RELEASE PopCallStack(); #endif }
int main() { FILE *input, *output; input=fopen("input.dat","r"); output=fopen("output.dat","w"); int x; char c[1024]; lista = (SENTINEL*) malloc(sizeof(SENTINEL)); lista->head=0; lista->tail=0; while(fscanf(input,"%s",c)!=EOF) { if(strcmp(c,"PRINT_ALL")==0) PRINT_ALL(output); else if(strcmp(c,"AF")==0) { fscanf(input,"%d",&x); AF(x); } else if(strcmp(c,"AL")==0) { fscanf(input,"%d",&x); AL(x); } else if(strcmp(c,"DF")==0) DF(); else if(strcmp(c,"DL")==0) DL(); else if(strcmp(c,"DOOM_THE_LIST")==0) DOOM_THE_LIST(); else if(strcmp(c,"DE")==0) { fscanf(input,"%d",&x); DE(x); } else if(strcmp(c,"PRINT_F")==0) { fscanf(input,"%d",&x); PRINT_F(x,output); } else if(strcmp(c,"PRINT_L")==0) { fscanf(input,"%d",&x); PRINT_L(x,output); } } return 0; }
inline void LocalTrrkKernel ( UpperOrLower uplo, Orientation orientationOfA, Orientation orientationOfB, T alpha, const DistMatrix<T,STAR,MC >& A, const DistMatrix<T,MR, STAR>& B, T beta, DistMatrix<T,MC, MR >& C ) { #ifndef RELEASE PushCallStack("LocalTrrkKernel"); CheckInput( orientationOfA, orientationOfB, A, B, C ); #endif const Grid& g = C.Grid(); DistMatrix<T,STAR,MC> AL(g), AR(g); DistMatrix<T,MR,STAR> BT(g), BB(g); DistMatrix<T,MC,MR> CTL(g), CTR(g), CBL(g), CBR(g); DistMatrix<T,MC,MR> DTL(g), DBR(g); const int half = C.Height()/2; ScaleTrapezoid( beta, LEFT, uplo, 0, C ); LockedPartitionRight( A, AL, AR, half ); LockedPartitionDown ( B, BT, BB, half ); PartitionDownDiagonal ( C, CTL, CTR, CBL, CBR, half ); DTL.AlignWith( CTL ); DBR.AlignWith( CBR ); DTL.ResizeTo( CTL.Height(), CTL.Width() ); DBR.ResizeTo( CBR.Height(), CBR.Width() ); //------------------------------------------------------------------------// if( uplo == LOWER ) internal::LocalGemm ( orientationOfA, orientationOfB, alpha, AR, BT, T(1), CBL ); else internal::LocalGemm ( orientationOfA, orientationOfB, alpha, AL, BB, T(1), CTR ); internal::LocalGemm ( orientationOfA, orientationOfB, alpha, AL, BT, T(0), DTL ); AxpyTriangle( uplo, T(1), DTL, CTL ); internal::LocalGemm ( orientationOfA, orientationOfB, alpha, AR, BB, T(0), DBR ); AxpyTriangle( uplo, T(1), DBR, CBR ); //------------------------------------------------------------------------// #ifndef RELEASE PopCallStack(); #endif }
int main() { FILE *g; l=0; head=NULL; tail=NULL; g=fopen("input.txt", "r"); char cuvant[15]; int n; if (g==NULL) { printf("Error in opening the file."); exit(1); } while(fscanf(g,"%s",cuvant)>0) { if (strcmp(cuvant,"AF")==0) { fscanf(g,"%d",&n); AF(n); } else if (strcmp(cuvant,"AL")==0) { fscanf(g,"%d",&n); AL(n); } else if (strcmp(cuvant,"DF")==0) DF(); else if(strcmp(cuvant,"DL")==0) DL(); else if(strcmp(cuvant,"DE")==0) { fscanf(g,"%d",&n); DE(n); } else if(strcmp(cuvant,"PRINT_ALL")==0) PRINT_ALL(); else if(strcmp(cuvant,"PRINT_F")==0) { fscanf(g,"%d",&n); PRINT_F(n); } else if(strcmp(cuvant,"PRINT_L")==0) { fscanf(g,"%d",&n); PRINT_L(n); } else if(strcmp(cuvant,"DOOM_THE_LIST")==0) DOOM_THE_LIST(); } fclose(g); printf("%d",l); return 0; }
int main() { FILE* g=fopen("input.dat", "r"); char t[20]; int value; sent=(sentinel*)malloc(sizeof(sentinel)); sent->head=NULL; sent->tail=NULL; while(fscanf(g, "%s", &t)==1) { if(strcmp(t, "AF")==0) { fscanf(g, "%d", &value); AF(value); } else if(strcmp(t, "AL")==0) { fscanf(g, "%d", &value); AL(value); } else if(strcmp(t, "DF")==0) DF(); else if(strcmp(t, "DL")==0) DL(); else if(strcmp(t, "DOOM_THE_LIST")==0) DOOM(); else if(strcmp(t, "DE")==0) { fscanf(g, "%d", &value); DELX(value); } else if(strcmp(t, "PRINT_ALL")==0) PrALL(); else if(strcmp(t, "PRINT_F")==0) { fscanf(g, "%d", &value); PrFx(value); } else if(strcmp(t, "PRINT_L")==0) { fscanf(g, "%d", &value); PrLx(value); } } fclose(g); return 0; }
void read() { FILE *pf=fopen("input.dat","r"); int time; while (fscanf(pf,"%d ",&time)==1) { AL(time); } int x,y; char name[20]; while (fscanf(pf,"%s %d %d",name,&x,&y)==3) { enqueue(x,y,name); } fclose(pf); }
optional<OpenalId> AudioDevice::getFreeSource() { RecursiveLock lock(mutex); for (int i : All(sources)) { auto& source = sources[i]; ALint state = 0; AL(alGetSourcei(source.getId(), AL_SOURCE_STATE, &state)); if (state == AL_STOPPED) { // recreating the source does a better job at cleaning up after streaming // without it the old buffer queue still existed source = SoundSource(); return source.getId(); } } if (sources.size() < maxSources) { sources.emplace_back(); return sources.back().getId(); } else return none; }
vector<int> sort_AL(vector<int> &SL , vector<int> &Text , vector<int> &RD) { vector<pair<pair<int, int> , int> > AL_to_sort(SL.size()); for (int i = 0 , n = (int)AL_to_sort.size() ; i < n ; ++i) { AL_to_sort[i].first = key(SL[i], Text, RD); AL_to_sort[i].second = SL[i]; } //sort AL and we have to make it radix after this sort(AL_to_sort.begin(), AL_to_sort.end()); vector<int> AL(AL_to_sort.size()); for (int i = 0 , n = (int) AL.size(); i < n ; ++i) { AL[i] = AL_to_sort[i].second; } AL_to_sort.clear(); return AL; }
klen -= GROUP_FILTER_SIZE(0); copylen = numsrc * sizeof(gf32->gf_slist[0]); if (copylen > klen) copylen = klen; if (copy_in_user(gf32->gf_slist, kgf->gf_slist, copylen)) return -EFAULT; } return err; } EXPORT_SYMBOL(compat_mc_getsockopt); /* Argument list sizes for compat_sys_socketcall */ #define AL(x) ((x) * sizeof(u32)) static unsigned char nas[21] = { AL(0), AL(3), AL(3), AL(3), AL(2), AL(3), AL(3), AL(3), AL(4), AL(4), AL(4), AL(6), AL(6), AL(2), AL(5), AL(5), AL(3), AL(3), AL(4), AL(5), AL(4) }; #undef AL asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg, unsigned int flags) { return sys_sendmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT); } asmlinkage long compat_sys_sendmmsg(int fd, struct compat_mmsghdr __user *mmsg, unsigned int vlen, unsigned int flags) { return __sys_sendmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
inline void Her2kLN ( T alpha, const DistMatrix<T,MC,MR>& A, const DistMatrix<T,MC,MR>& B, T beta, DistMatrix<T,MC,MR>& C ) { #ifndef RELEASE PushCallStack("internal::Her2kLN"); if( A.Grid() != B.Grid() || B.Grid() != C.Grid() ) throw std::logic_error ("{A,B,C} must be distributed over the same grid"); if( A.Height() != C.Height() || A.Height() != C.Width() || B.Height() != C.Height() || B.Height() != C.Width() || A.Width() != B.Width() ) { std::ostringstream msg; msg << "Nonconformal Her2kLN:\n" << " A ~ " << A.Height() << " x " << A.Width() << "\n" << " B ~ " << B.Height() << " x " << B.Width() << "\n" << " C ~ " << C.Height() << " x " << C.Width() << "\n"; throw std::logic_error( msg.str() ); } #endif const Grid& g = A.Grid(); // Matrix views DistMatrix<T,MC,MR> AL(g), AR(g), A0(g), A1(g), A2(g); DistMatrix<T,MC,MR> BL(g), BR(g), B0(g), B1(g), B2(g); // Temporary distributions DistMatrix<T,MC, STAR> A1_MC_STAR(g); DistMatrix<T,MC, STAR> B1_MC_STAR(g); DistMatrix<T,VR, STAR> A1_VR_STAR(g); DistMatrix<T,VR, STAR> B1_VR_STAR(g); DistMatrix<T,STAR,MR > A1Adj_STAR_MR(g); DistMatrix<T,STAR,MR > B1Adj_STAR_MR(g); A1_MC_STAR.AlignWith( C ); B1_MC_STAR.AlignWith( C ); A1_VR_STAR.AlignWith( C ); B1_VR_STAR.AlignWith( C ); A1Adj_STAR_MR.AlignWith( C ); B1Adj_STAR_MR.AlignWith( C ); // Start the algorithm ScaleTrapezoid( beta, LEFT, LOWER, 0, C ); LockedPartitionRight( A, AL, AR, 0 ); LockedPartitionRight( B, BL, BR, 0 ); while( AR.Width() > 0 ) { LockedRepartitionRight ( AL, /**/ AR, A0, /**/ A1, A2 ); LockedRepartitionRight ( BL, /**/ BR, B0, /**/ B1, B2 ); //--------------------------------------------------------------------// A1_VR_STAR = A1_MC_STAR = A1; A1Adj_STAR_MR.AdjointFrom( A1_VR_STAR ); B1_VR_STAR = B1_MC_STAR = B1; B1Adj_STAR_MR.AdjointFrom( B1_VR_STAR ); LocalTrr2k ( LOWER, alpha, A1_MC_STAR, B1Adj_STAR_MR, B1_MC_STAR, A1Adj_STAR_MR, T(1), C ); //--------------------------------------------------------------------// SlideLockedPartitionRight ( AL, /**/ AR, A0, A1, /**/ A2 ); SlideLockedPartitionRight ( BL, /**/ BR, B0, B1, /**/ B2 ); } #ifndef RELEASE PopCallStack(); #endif }
} return err; } asmlinkage long compat_sys_getsockopt(int fd, int level, int optname, char __user *optval, int __user *optlen) { if (level == SOL_SOCKET && (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)) return do_get_sock_timeout(fd, level, optname, optval, optlen); return sys_getsockopt(fd, level, optname, optval, optlen); } /* Argument list sizes for compat_sys_socketcall */ #define AL(x) ((x) * sizeof(u32)) static unsigned char nas[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), AL(3),AL(3),AL(4),AL(4),AL(4),AL(6), AL(6),AL(2),AL(5),AL(5),AL(3),AL(3)}; #undef AL asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg, unsigned flags) { return sys_sendmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT); } asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg, unsigned int flags) { return sys_recvmsg(fd, (struct msghdr __user *)msg, flags | MSG_CMSG_COMPAT); } asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
void Trr2kNNNT ( UpperOrLower uplo, Orientation orientationOfD, T alpha, const DistMatrix<T>& A, const DistMatrix<T>& B, const DistMatrix<T>& C, const DistMatrix<T>& D, T beta, DistMatrix<T>& E ) { #ifndef RELEASE PushCallStack("internal::Trr2kNNNT"); if( E.Height() != E.Width() || A.Width() != C.Width() || A.Height() != E.Height() || C.Height() != E.Height() || B.Width() != E.Width() || D.Height() != E.Width() || A.Width() != B.Height() || C.Width() != D.Width() ) throw std::logic_error("Nonconformal Trr2kNNNT"); #endif const Grid& g = E.Grid(); DistMatrix<T> AL(g), AR(g), A0(g), A1(g), A2(g); DistMatrix<T> BT(g), B0(g), BB(g), B1(g), B2(g); DistMatrix<T> CL(g), CR(g), C0(g), C1(g), C2(g); DistMatrix<T> DL(g), DR(g), D0(g), D1(g), D2(g); DistMatrix<T,MC, STAR> A1_MC_STAR(g); DistMatrix<T,MR, STAR> B1Trans_MR_STAR(g); DistMatrix<T,MC, STAR> C1_MC_STAR(g); DistMatrix<T,VR, STAR> D1_VR_STAR(g); DistMatrix<T,STAR,MR > D1AdjOrTrans_STAR_MR(g); A1_MC_STAR.AlignWith( E ); B1Trans_MR_STAR.AlignWith( E ); C1_MC_STAR.AlignWith( E ); D1_VR_STAR.AlignWith( E ); D1AdjOrTrans_STAR_MR.AlignWith( E ); LockedPartitionRight( A, AL, AR, 0 ); LockedPartitionDown ( B, BT, BB, 0 ); LockedPartitionRight( C, CL, CR, 0 ); LockedPartitionRight( D, DL, DR, 0 ); while( AL.Width() < A.Width() ) { LockedRepartitionRight ( AL, /**/ AR, A0, /**/ A1, A2 ); LockedRepartitionDown ( BT, B0, /**/ /**/ B1, BB, B2 ); LockedRepartitionRight ( CL, /**/ CR, C0, /**/ C1, C2 ); LockedRepartitionRight ( CL, /**/ CR, C0, /**/ C1, C2 ); //--------------------------------------------------------------------// A1_MC_STAR = A1; C1_MC_STAR = C1; B1Trans_MR_STAR.TransposeFrom( B1 ); D1_VR_STAR = D1; if( orientationOfD == ADJOINT ) D1AdjOrTrans_STAR_MR.AdjointFrom( D1_VR_STAR ); else D1AdjOrTrans_STAR_MR.TransposeFrom( D1_VR_STAR ); LocalTrr2k ( uplo, TRANSPOSE, alpha, A1_MC_STAR, B1Trans_MR_STAR, C1_MC_STAR, D1AdjOrTrans_STAR_MR, beta, E ); //--------------------------------------------------------------------// SlideLockedPartitionRight ( DL, /**/ DR, D0, D1, /**/ D2 ); SlideLockedPartitionRight ( CL, /**/ CR, C0, C1, /**/ C2 ); SlideLockedPartitionDown ( BT, B0, B1, /**/ /**/ BB, B2 ); SlideLockedPartitionRight ( AL, /**/ AR, A0, A1, /**/ A2 ); } #ifndef RELEASE PopCallStack(); #endif }
int HashmapExercise(int verbose, struct cfg *cfg, char *args[]) { struct hashmap *h; int rate = 0, i, n = 0; int count = atoi(args[0]); int interval = atoi(args[1]); iter_t riter; iter_t iter; char *str; struct allocator *al = NULL; char *mem; clock_t t0; int chkpnt = 0; struct allocator *hal; if ((mem = malloc(0xFFFFFF)) == NULL || (al = suba_init(mem, 0xFFFFFF, 1, 0)) == NULL || (h = hashmap_new(hash_str, cmp_str, NULL, al)) == NULL) { AMSG(""); return -1; } hal = AL(h); /* if ((h = hashmap_new(hash_str, cmp_str, NULL, al)) == NULL) { AMSG(""); return -1; } */ srand(0); t0 = clock(); if (verbose) fprintf(stderr, "\n time count size mem\n"); hashmap_iterate(h, &iter); rate_iterate(&riter); for (i = 0; i < count; i++) { if ((i % interval) == 0) { if (verbose) fprintf(stderr, "%2d %8ld %8d %8d %8d\n", chkpnt++, (clock() - t0) / 1000, hashmap_size(h), table_sizes[h->table_size_index], hal->alloc_total - hal->free_total); rate = rate_next(&riter); } if (rand() % 10 < rate) { str = allocator_alloc(NULL, 8, 0); sprintf(str, "%07d", n++); if (hashmap_put(h, str, str) == -1) { AMSG(""); return -1; } else { /*fputc('+', stderr); */ tcase_printf(verbose, "put %s %d\r", str, hashmap_size(h)); } } else { if (hashmap_is_empty(h)) { /*fputc('0', stderr); */ tcase_printf(verbose, "hashmap empty\r"); } else { str = hashmap_next(h, &iter); if (str) { char *data; tcase_printf(verbose, "get %s %d\r", str, hashmap_size(h)); if (hashmap_remove(h, (void **)&str, (void **)&data) == -1) { AMSG(""); return -1; } /*fputc('-', stderr); */ tcase_printf(verbose, "rem %s %d\r", str, hashmap_size(h)); allocator_free(NULL, str); } else { /*fputc('x', stderr); */ tcase_printf(verbose, "nothing left to iterate over\r"); hashmap_iterate(h, &iter); } } } } if (verbose) fprintf(stderr, "%2d %8ld %8d %8d %8d\n", chkpnt++, (clock() - t0) / 1000, hashmap_size(h), table_sizes[h->table_size_index], hal->alloc_total - hal->free_total); hashmap_del(h, allocator_free, NULL, NULL); /* free(mem); */ if (verbose) fprintf(stderr, "bytes outstanding from allocator: %d\n", hal->alloc_total - hal->free_total); cfg = NULL; return 0; }
inline void GemmTTB ( Orientation orientationOfA, Orientation orientationOfB, T alpha, const DistMatrix<T>& A, const DistMatrix<T>& B, T beta, DistMatrix<T>& C ) { #ifndef RELEASE PushCallStack("internal::GemmTTB"); if( A.Grid() != B.Grid() || B.Grid() != C.Grid() ) throw std::logic_error ("{A,B,C} must be distributed over the same grid"); if( orientationOfA == NORMAL || orientationOfB == NORMAL ) throw std::logic_error ("GemmTTB expects A and B to be (Conjugate)Transposed"); if( A.Width() != C.Height() || B.Height() != C.Width() || A.Height() != B.Width() ) { std::ostringstream msg; msg << "Nonconformal GemmTTB: \n" << " A ~ " << A.Height() << " x " << A.Width() << "\n" << " B ~ " << B.Height() << " x " << B.Width() << "\n" << " C ~ " << C.Height() << " x " << C.Width() << "\n"; throw std::logic_error( msg.str().c_str() ); } #endif const Grid& g = A.Grid(); // Matrix views DistMatrix<T> AL(g), AR(g), A0(g), A1(g), A2(g); DistMatrix<T> CT(g), C0(g), CB(g), C1(g), C2(g); // Temporary distributions DistMatrix<T,VR, STAR> A1_VR_STAR(g); DistMatrix<T,STAR,MR > A1AdjOrTrans_STAR_MR(g); DistMatrix<T,STAR,MC > D1_STAR_MC(g); DistMatrix<T,MR, MC > D1_MR_MC(g); DistMatrix<T> D1(g); A1_VR_STAR.AlignWith( B ); A1AdjOrTrans_STAR_MR.AlignWith( B ); D1_STAR_MC.AlignWith( B ); // Start the algorithm Scale( beta, C ); LockedPartitionRight( A, AL, AR, 0 ); PartitionDown ( C, CT, CB, 0 ); while( AR.Width() > 0 ) { LockedRepartitionRight ( AL, /**/ AR, A0, /**/ A1, A2 ); RepartitionDown ( CT, C0, /**/ /**/ C1, CB, C2 ); D1.AlignWith( C1 ); Zeros( C1.Height(), C1.Width(), D1_STAR_MC ); //--------------------------------------------------------------------// A1_VR_STAR = A1; if( orientationOfA == ADJOINT ) A1AdjOrTrans_STAR_MR.AdjointFrom( A1_VR_STAR ); else A1AdjOrTrans_STAR_MR.TransposeFrom( A1_VR_STAR ); // D1[*,MC] := alpha (A1[MR,*])^[T/H] (B[MC,MR])^[T/H] // = alpha (A1^[T/H])[*,MR] (B^[T/H])[MR,MC] LocalGemm ( NORMAL, orientationOfB, alpha, A1AdjOrTrans_STAR_MR, B, T(0), D1_STAR_MC ); // C1[MC,MR] += scattered & transposed D1[*,MC] summed over grid rows D1_MR_MC.SumScatterFrom( D1_STAR_MC ); D1 = D1_MR_MC; Axpy( T(1), D1, C1 ); //--------------------------------------------------------------------// D1.FreeAlignments(); SlideLockedPartitionRight ( AL, /**/ AR, A0, A1, /**/ A2 ); SlidePartitionDown ( CT, C0, C1, /**/ /**/ CB, C2 ); } #ifndef RELEASE PopCallStack(); #endif }
int32_t env_linux_hook_socketcall(struct emu_env *env, struct emu_env_hook *hook) { struct emu_cpu *c = emu_cpu_get(env->emu); #define AL(x) (x) static unsigned char nargs[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), AL(3),AL(3),AL(4),AL(4),AL(4),AL(6), AL(6),AL(2),AL(5),AL(5),AL(3),AL(3)}; #undef AL uint32_t a[6]; int i; for ( i=0;i<nargs[c->reg[ebx]];i++ ) { emu_memory_read_dword(emu_memory_get(c->emu),c->reg[ecx]+4*i,a+i); } uint32_t returnvalue = 0; switch ( c->reg[ebx] ) { case 1: // SYS_SOCKET printf("int socket(int domain=%i, int type=%i, int protocol=%i);\n", a[0], a[1], a[2]); if (hook->hook.lin->userhook != NULL) returnvalue = hook->hook.lin->userhook(env, hook, a[0], a[1], a[2]); else returnvalue = 14; if ( env->profile != NULL ) { emu_profile_function_add(env->profile, "socket"); emu_profile_argument_add_int(env->profile, "int", "domain", a[0]); emu_profile_argument_add_int(env->profile, "int", "type", a[1]); emu_profile_argument_add_int(env->profile, "int", "protocol", a[2]); emu_profile_function_returnvalue_int_set(env->profile, "int", returnvalue); } emu_cpu_reg32_set(c, eax, returnvalue); break; case 2: // SYS_BIND { /* printf("int bind(int sockfd=%i, struct sockaddr *my_addr=%08x={host %s port %i}, int addrlen);\n", a[0], a[1], inet_ntoa(*(struct in_addr *)&((struct sockaddr_in *)&sa)->sin_addr), ntohs(((struct sockaddr_in *)&sa)->sin_port) ); */ struct sockaddr sa; memset(&sa, 0, sizeof(struct sockaddr)); emu_memory_read_block(emu_memory_get(c->emu), a[1], &sa, sizeof(struct sockaddr)); if (hook->hook.lin->userhook != NULL) returnvalue = hook->hook.lin->userhook(env, hook, a[0], &sa, a[2]); else returnvalue = 0; if (env->profile != NULL) { emu_profile_function_add(env->profile, "bind"); emu_profile_argument_add_int(env->profile, "int", "sockfd", a[0]); emu_profile_argument_add_sockaddr_ptr(env->profile, "my_addr", a[1], sa); emu_profile_argument_add_int(env->profile, "int", "addrlen", a[2]); emu_profile_function_returnvalue_int_set(env->profile, "int", returnvalue); } emu_cpu_reg32_set(c, eax, returnvalue); } break; case 3: // SYS_CONNECT { printf("connect\n"); struct sockaddr sa; memset(&sa, 0, sizeof(struct sockaddr)); emu_memory_read_block(emu_memory_get(c->emu), a[1], &sa, sizeof(struct sockaddr)); if (hook->hook.lin->userhook != NULL) returnvalue = hook->hook.lin->userhook(env, hook, a[0], &sa, a[2]); else returnvalue = 0; if (env->profile != NULL) { emu_profile_function_add(env->profile, "connect"); emu_profile_argument_add_int(env->profile, "int", "sockfd", a[0]); emu_profile_argument_add_sockaddr_ptr(env->profile, "serv_addr", a[1], sa); emu_profile_argument_add_int(env->profile, "int", "addrlen", a[2]); emu_profile_function_returnvalue_int_set(env->profile, "int", returnvalue); } emu_cpu_reg32_set(c, eax, returnvalue); } break; case 4: // SYS_LISTEN printf("int listen(int s=%i, int backlog=%i);\n", a[0], a[1]); if (hook->hook.lin->userhook != NULL) returnvalue = hook->hook.lin->userhook(env, hook, a[0], a[1]); else returnvalue = 0; if (env->profile != NULL) { emu_profile_function_add(env->profile, "listen"); emu_profile_argument_add_int(env->profile, "int", "s", a[0]); emu_profile_argument_add_int(env->profile, "int", "backlog", a[1]); emu_profile_function_returnvalue_int_set(env->profile, "int", returnvalue); } emu_cpu_reg32_set(c, eax, returnvalue); break; case 5: // SYS_ACCEPT printf("int accept(int s=%i, struct sockaddr *addr=%08x, int *addrlen=%08x);\n", a[0], a[1], a[2]); struct sockaddr sa; memset(&sa, 0, sizeof(struct sockaddr)); emu_memory_read_block(emu_memory_get(c->emu), a[1], &sa, sizeof(struct sockaddr)); if (hook->hook.lin->userhook != NULL) returnvalue = hook->hook.lin->userhook(env, hook, a[0], &sa, a[2]); else returnvalue = 19; if (env->profile != NULL) { emu_profile_function_add(env->profile, "accept"); emu_profile_argument_add_int(env->profile, "int", "sockfd", a[0]); emu_profile_argument_add_ptr(env->profile, "sockaddr_in *", "addr", a[1]); emu_profile_argument_add_none(env->profile); emu_profile_argument_add_ptr(env->profile, "int", "addrlen", a[2]); emu_profile_argument_add_none(env->profile); emu_profile_function_returnvalue_int_set(env->profile, "int", returnvalue); } emu_cpu_reg32_set(c, eax, returnvalue); break; case 6: // SYS_GETSOCKNAME printf("sys_getsockname(2)\n"); break; case 7: // SYS_GETPEERNAME printf("sys_getpeername(2)\n"); break; case 8: // SYS_SOCKETPAIR printf("sys_socketpair(2)\n"); break; case 9: // SYS_SEND printf("sys_send(2)\n"); break; case 10: // SYS_RECV printf("sys_recv(2)\n"); break; case 11: // SYS_SENDTO printf("sys_sendto(2)\n"); break; case 12: // SYS_RECVFROM printf("sys_recvfrom(2)\n"); break; case 13: // SYS_SHUTDOWN printf("sys_shutdown(2)\n"); break; case 14: // SYS_SETSOCKOPT printf("sys_setsockopt(2)\n"); break; case 15: // SYS_GETSOCKOPT printf("sys_getsockopt(2)\n"); break; case 16: // SYS_SENDMSG printf("sys_sendmsg(2)\n"); break; case 17: // SYS_RECVMSG printf("sys_recvmsg(2)\n"); break; default: printf("syscall %i (%x) unknown", c->reg[ebx], c->reg[ebx]); } return 0; }
inline void GemmNNC ( T alpha, const DistMatrix<T>& A, const DistMatrix<T>& B, T beta, DistMatrix<T>& C ) { #ifndef RELEASE PushCallStack("internal::GemmNNC"); if( A.Grid() != B.Grid() || B.Grid() != C.Grid() ) throw std::logic_error ("{A,B,C} must be distributed over the same grid"); if( A.Height() != C.Height() || B.Width() != C.Width() || A.Width() != B.Height() ) { std::ostringstream msg; msg << "Nonconformal GemmNNC: \n" << " A ~ " << A.Height() << " x " << A.Width() << "\n" << " B ~ " << B.Height() << " x " << B.Width() << "\n" << " C ~ " << C.Height() << " x " << C.Width() << "\n"; throw std::logic_error( msg.str().c_str() ); } #endif const Grid& g = A.Grid(); // Matrix views DistMatrix<T> AL(g), AR(g), A0(g), A1(g), A2(g); DistMatrix<T> BT(g), B0(g), BB(g), B1(g), B2(g); // Temporary distributions DistMatrix<T,MC,STAR> A1_MC_STAR(g); DistMatrix<T,MR,STAR> B1Trans_MR_STAR(g); A1_MC_STAR.AlignWith( C ); B1Trans_MR_STAR.AlignWith( C ); // Start the algorithm Scale( beta, C ); LockedPartitionRight( A, AL, AR, 0 ); LockedPartitionDown ( B, BT, BB, 0 ); while( AR.Width() > 0 ) { LockedRepartitionRight( AL, /**/ AR, A0, /**/ A1, A2 ); LockedRepartitionDown( BT, B0, /**/ /**/ B1, BB, B2 ); //--------------------------------------------------------------------// A1_MC_STAR = A1; B1Trans_MR_STAR.TransposeFrom( B1 ); // C[MC,MR] += alpha A1[MC,*] (B1^T[MR,*])^T // = alpha A1[MC,*] B1[*,MR] LocalGemm ( NORMAL, TRANSPOSE, alpha, A1_MC_STAR, B1Trans_MR_STAR, T(1), C ); //--------------------------------------------------------------------// SlideLockedPartitionRight( AL, /**/ AR, A0, A1, /**/ A2 ); SlideLockedPartitionDown( BT, B0, B1, /**/ /**/ BB, B2 ); } #ifndef RELEASE PopCallStack(); #endif }
int main( int argc, char* argv[] ) { El::Environment env( argc, argv ); try { typedef double Real; typedef El::Complex<Real> Scalar; const El::Int m = El::Input("--height","height of matrix",20); const El::Int n = El::Input("--width","width of matrix",100); const El::Int r = El::Input("--rank","rank of matrix",5); const El::Int maxSteps = El::Input("--maxSteps","max # of steps of QR",10); const Real tol = El::Input("--tol","tolerance for ID",Real(-1)); const bool print = El::Input("--print","print matrices?",false); const bool smallestFirst = El::Input("--smallestFirst","smallest norm first?",false); El::ProcessInput(); El::PrintInputReport(); El::mpi::Comm comm = El::mpi::COMM_WORLD; const El::Grid& grid = El::Grid::Default(); El::DistMatrix<Scalar> U(grid), V(grid), A(grid); El::Uniform( U, m, r ); El::Uniform( V, n, r ); El::Gemm( El::NORMAL, El::ADJOINT, Scalar(1), U, V, A ); const Real frobA = El::FrobeniusNorm( A ); if( print ) El::Print( A, "A" ); El::DistPermutation Omega(grid); El::DistMatrix<Scalar,El::STAR,El::VR> Z(grid); El::QRCtrl<Real> ctrl; ctrl.boundRank = true; ctrl.maxRank = maxSteps; if( tol != -1. ) { ctrl.adaptive = true; ctrl.tol = tol; } ctrl.smallestFirst = smallestFirst; El::Timer timer; if( El::mpi::Rank(comm) == 0 ) timer.Start(); El::ID( A, Omega, Z, ctrl ); if( El::mpi::Rank(comm) == 0 ) timer.Stop(); const El::Int rank = Z.Height(); if( print ) { El::DistMatrix<El::Int> OmegaFull(grid); Omega.ExplicitMatrix( OmegaFull ); El::Print( OmegaFull, "Omega" ); El::Print( Z, "Z" ); } // Pivot A and form the matrix of its (hopefully) dominant columns El::Timer permTimer("permTimer"); permTimer.Start(); Omega.PermuteCols( A ); permTimer.Stop(); auto hatA( A ); hatA.Resize( m, rank ); if( print ) { El::Print( A, "A Omega^T" ); El::Print( hatA, "\\hat{A}" ); } // Check || A Omega^T - \hat{A} [I, Z] ||_F / || A ||_F El::DistMatrix<Scalar> AL(grid), AR(grid); El::PartitionRight( A, AL, AR, rank ); El::Zero( AL ); { El::DistMatrix<Scalar,El::MC,El::STAR> hatA_MC_STAR(grid); El::DistMatrix<Scalar,El::STAR,El::MR> Z_STAR_MR(grid); hatA_MC_STAR.AlignWith( AR ); Z_STAR_MR.AlignWith( AR ); hatA_MC_STAR = hatA; Z_STAR_MR = Z; El::LocalGemm ( El::NORMAL, El::NORMAL, Scalar(-1), hatA_MC_STAR, Z_STAR_MR, Scalar(1), AR ); } const Real frobError = El::FrobeniusNorm( A ); if( print ) El::Print( A, "A Omega^T - \\hat{A} [I, Z]" ); if( El::mpi::Rank(comm) == 0 ) { El::Output(" ID time: ",timer.Total()," secs"); El::Output ("|| A ||_F = ",frobA,"\n", "|| A Omega^T - \\hat{A} [I, Z] ||_F / || A ||_F = ", frobError/frobA); } } catch( std::exception& e ) { El::ReportException(e); } return 0; }
void Trr2kNTTN ( UpperOrLower uplo, Orientation orientationOfB, Orientation orientationOfC, T alpha, const DistMatrix<T>& A, const DistMatrix<T>& B, const DistMatrix<T>& C, const DistMatrix<T>& D, T beta, DistMatrix<T>& E ) { #ifndef RELEASE CallStackEntry entry("internal::Trr2kNTTN"); if( E.Height() != E.Width() || A.Width() != C.Height() || A.Height() != E.Height() || C.Width() != E.Height() || B.Height() != E.Width() || D.Width() != E.Width() || A.Width() != B.Width() || C.Height() != D.Height() ) LogicError("Nonconformal Trr2kNTTN"); #endif const Grid& g = E.Grid(); DistMatrix<T> AL(g), AR(g), A0(g), A1(g), A2(g); DistMatrix<T> BL(g), BR(g), B0(g), B1(g), B2(g); DistMatrix<T> CT(g), C0(g), CB(g), C1(g), C2(g); DistMatrix<T> DT(g), D0(g), DB(g), D1(g), D2(g); DistMatrix<T,MC, STAR> A1_MC_STAR(g); DistMatrix<T,VR, STAR> B1_VR_STAR(g); DistMatrix<T,STAR,MR > B1AdjOrTrans_STAR_MR(g); DistMatrix<T,STAR,MC > C1_STAR_MC(g); DistMatrix<T,MR, STAR> D1Trans_MR_STAR(g); A1_MC_STAR.AlignWith( E ); B1_VR_STAR.AlignWith( E ); B1AdjOrTrans_STAR_MR.AlignWith( E ); C1_STAR_MC.AlignWith( E ); D1Trans_MR_STAR.AlignWith( E ); LockedPartitionRight( A, AL, AR, 0 ); LockedPartitionRight( B, BL, BR, 0 ); LockedPartitionDown ( C, CT, CB, 0 ); LockedPartitionDown ( D, DT, DB, 0 ); while( AL.Width() < A.Width() ) { LockedRepartitionRight ( AL, /**/ AR, A0, /**/ A1, A2 ); LockedRepartitionRight ( BL, /**/ BR, B0, /**/ B1, B2 ); LockedRepartitionDown ( CT, C0, /**/ /**/ C1, CB, C2 ); LockedRepartitionDown ( DT, D0, /**/ /**/ D1, DB, D2 ); //--------------------------------------------------------------------// A1_MC_STAR = A1; C1_STAR_MC = C1; B1_VR_STAR = B1; if( orientationOfB == ADJOINT ) B1AdjOrTrans_STAR_MR.AdjointFrom( B1_VR_STAR ); else B1AdjOrTrans_STAR_MR.TransposeFrom( B1_VR_STAR ); D1Trans_MR_STAR.TransposeFrom( D1 ); LocalTrr2k ( uplo, orientationOfC, TRANSPOSE, alpha, A1_MC_STAR, B1AdjOrTrans_STAR_MR, C1_STAR_MC, D1Trans_MR_STAR, beta, E ); //--------------------------------------------------------------------// SlideLockedPartitionRight ( AL, /**/ AR, A0, A1, /**/ A2 ); SlideLockedPartitionRight ( BL, /**/ BR, B0, B1, /**/ B2 ); SlideLockedPartitionDown ( CT, C0, C1, /**/ /**/ CB, C2 ); SlideLockedPartitionDown ( DT, D0, D1, /**/ /**/ DB, D2 ); } }
void ApplyPackedReflectorsRUHF ( Conjugation conjugation, int offset, const DistMatrix<Complex<R> >& H, const DistMatrix<Complex<R>,MD,STAR>& t, DistMatrix<Complex<R> >& A ) { #ifndef RELEASE PushCallStack("internal::ApplyPackedReflectorsRUHF"); if( H.Grid() != t.Grid() || t.Grid() != A.Grid() ) throw std::logic_error ("{H,t,A} must be distributed over the same grid"); if( offset < 0 || offset > H.Width() ) throw std::logic_error("Transforms out of bounds"); if( H.Width() != A.Width() ) throw std::logic_error ("Length of transforms must equal width of target matrix"); if( t.Height() != H.DiagonalLength( offset ) ) throw std::logic_error("t must be the same length as H's offset diag"); if( !t.AlignedWithDiagonal( H, offset ) ) throw std::logic_error("t must be aligned with H's 'offset' diagonal"); #endif typedef Complex<R> C; const Grid& g = H.Grid(); DistMatrix<C> HTL(g), HTR(g), H00(g), H01(g), H02(g), HPan(g), HPanCopy(g), HBL(g), HBR(g), H10(g), H11(g), H12(g), H20(g), H21(g), H22(g); DistMatrix<C> AL(g), AR(g), A0(g), A1(g), A2(g); DistMatrix<C,MD,STAR> tT(g), t0(g), tB(g), t1(g), t2(g); DistMatrix<C,STAR,VR > HPan_STAR_VR(g); DistMatrix<C,STAR,MR > HPan_STAR_MR(g); DistMatrix<C,STAR,STAR> t1_STAR_STAR(g); DistMatrix<C,STAR,STAR> SInv_STAR_STAR(g); DistMatrix<C,STAR,MC > ZAdj_STAR_MC(g); DistMatrix<C,STAR,VC > ZAdj_STAR_VC(g); LockedPartitionDownDiagonal ( H, HTL, HTR, HBL, HBR, 0 ); LockedPartitionDown ( t, tT, tB, 0 ); PartitionRight ( A, AL, AR, 0 ); while( HTL.Height() < H.Height() && HTL.Width() < H.Width() ) { LockedRepartitionDownDiagonal ( HTL, /**/ HTR, H00, /**/ H01, H02, /*************/ /******************/ /**/ H10, /**/ H11, H12, HBL, /**/ HBR, H20, /**/ H21, H22 ); const int HPanWidth = H11.Width() + H12.Width(); const int HPanHeight = std::min( H11.Height(), std::max(HPanWidth-offset,0) ); LockedView( HPan, H, H00.Height(), H00.Width(), HPanHeight, HPanWidth ); LockedRepartitionDown ( tT, t0, /**/ /**/ t1, tB, t2, HPanHeight ); RepartitionRight ( AL, /**/ AR, A0, /**/ A1, A2 ); HPan_STAR_MR.AlignWith( AR ); ZAdj_STAR_MC.AlignWith( AR ); ZAdj_STAR_VC.AlignWith( AR ); Zeros( HPanHeight, AR.Height(), ZAdj_STAR_MC ); Zeros( HPanHeight, HPanHeight, SInv_STAR_STAR ); //--------------------------------------------------------------------// HPanCopy = HPan; MakeTrapezoidal( LEFT, UPPER, offset, HPanCopy ); SetDiagonalToOne( LEFT, offset, HPanCopy ); HPan_STAR_VR = HPanCopy; Herk ( UPPER, NORMAL, C(1), HPan_STAR_VR.LockedLocalMatrix(), C(0), SInv_STAR_STAR.LocalMatrix() ); SInv_STAR_STAR.SumOverGrid(); t1_STAR_STAR = t1; FixDiagonal( conjugation, t1_STAR_STAR, SInv_STAR_STAR ); HPan_STAR_MR = HPan_STAR_VR; LocalGemm ( NORMAL, ADJOINT, C(1), HPan_STAR_MR, AR, C(0), ZAdj_STAR_MC ); ZAdj_STAR_VC.SumScatterFrom( ZAdj_STAR_MC ); LocalTrsm ( LEFT, UPPER, ADJOINT, NON_UNIT, C(1), SInv_STAR_STAR, ZAdj_STAR_VC ); ZAdj_STAR_MC = ZAdj_STAR_VC; LocalGemm ( ADJOINT, NORMAL, C(-1), ZAdj_STAR_MC, HPan_STAR_MR, C(1), AR ); //--------------------------------------------------------------------// HPan_STAR_MR.FreeAlignments(); ZAdj_STAR_MC.FreeAlignments(); ZAdj_STAR_VC.FreeAlignments(); SlidePartitionRight ( AL, /**/ AR, A0, A1, /**/ A2 ); SlideLockedPartitionDown ( tT, t0, t1, /**/ /**/ tB, t2 ); SlideLockedPartitionDownDiagonal ( HTL, /**/ HTR, H00, H01, /**/ H02, /**/ H10, H11, /**/ H12, /*************/ /******************/ HBL, /**/ HBR, H20, H21, /**/ H22 ); } #ifndef RELEASE PopCallStack(); #endif }
inline void ApplyPackedReflectorsRUHF ( int offset, const DistMatrix<R>& H, DistMatrix<R>& A ) { #ifndef RELEASE PushCallStack("internal::ApplyPackedReflectorsRUHF"); if( H.Grid() != A.Grid() ) throw std::logic_error("{H,A} must be distributed over the same grid"); if( offset < 0 || offset > H.Width() ) throw std::logic_error("Transforms out of bounds"); if( H.Width() != A.Width() ) throw std::logic_error ("Length of transforms must equal width of target matrix"); #endif const Grid& g = H.Grid(); DistMatrix<R> HTL(g), HTR(g), H00(g), H01(g), H02(g), HPan(g), HPanCopy(g), HBL(g), HBR(g), H10(g), H11(g), H12(g), H20(g), H21(g), H22(g); DistMatrix<R> AL(g), AR(g), A0(g), A1(g), A2(g); DistMatrix<R,STAR,VR > HPan_STAR_VR(g); DistMatrix<R,STAR,MR > HPan_STAR_MR(g); DistMatrix<R,STAR,STAR> SInv_STAR_STAR(g); DistMatrix<R,STAR,MC > ZTrans_STAR_MC(g); DistMatrix<R,STAR,VC > ZTrans_STAR_VC(g); LockedPartitionDownDiagonal ( H, HTL, HTR, HBL, HBR, 0 ); PartitionRight( A, AL, AR, 0 ); while( HTL.Height() < H.Height() && HTL.Width() < H.Width() ) { LockedRepartitionDownDiagonal ( HTL, /**/ HTR, H00, /**/ H01, H02, /**************/ /******************/ /**/ H10, /**/ H11, H12, HBL, /**/ HBR, H20, /**/ H21, H22 ); RepartitionRight ( AL, /**/ AR, A0, /**/ A1, A2 ); const int HPanWidth = H11.Width() + H12.Width(); const int HPanHeight = std::min( H11.Height(), std::max(HPanWidth-offset,0) ); LockedView( HPan, H, H00.Height(), H00.Width(), HPanHeight, HPanWidth ); HPan_STAR_MR.AlignWith( AR ); ZTrans_STAR_MC.AlignWith( AR ); ZTrans_STAR_VC.AlignWith( AR ); Zeros( HPanHeight, AR.Height(), ZTrans_STAR_MC ); Zeros( HPanHeight, HPanHeight, SInv_STAR_STAR ); //--------------------------------------------------------------------// HPanCopy = HPan; MakeTrapezoidal( LEFT, UPPER, offset, HPanCopy ); SetDiagonalToOne( LEFT, offset, HPanCopy ); HPan_STAR_VR = HPanCopy; Syrk ( UPPER, NORMAL, R(1), HPan_STAR_VR.LockedLocalMatrix(), R(0), SInv_STAR_STAR.LocalMatrix() ); SInv_STAR_STAR.SumOverGrid(); HalveMainDiagonal( SInv_STAR_STAR ); HPan_STAR_MR = HPan_STAR_VR; LocalGemm ( NORMAL, TRANSPOSE, R(1), HPan_STAR_MR, AR, R(0), ZTrans_STAR_MC ); ZTrans_STAR_VC.SumScatterFrom( ZTrans_STAR_MC ); LocalTrsm ( LEFT, UPPER, TRANSPOSE, NON_UNIT, R(1), SInv_STAR_STAR, ZTrans_STAR_VC ); ZTrans_STAR_MC = ZTrans_STAR_VC; LocalGemm ( TRANSPOSE, NORMAL, R(-1), ZTrans_STAR_MC, HPan_STAR_MR, R(1), AR ); //--------------------------------------------------------------------// HPan_STAR_MR.FreeAlignments(); ZTrans_STAR_MC.FreeAlignments(); ZTrans_STAR_VC.FreeAlignments(); SlidePartitionRight ( AL, /**/ AR, A0, A1, /**/ A2 ); SlideLockedPartitionDownDiagonal ( HTL, /**/ HTR, H00, H01, /**/ H02, /**/ H10, H11, /**/ H12, /*************/ /******************/ HBL, /**/ HBR, H20, H21, /**/ H22 ); } #ifndef RELEASE PopCallStack(); #endif }
void RLVF ( Conjugation conjugation, Int offset, const DistMatrix<F>& H, const DistMatrix<F,MD,STAR>& t, DistMatrix<F>& A ) { #ifndef RELEASE CallStackEntry cse("apply_packed_reflectors::RLVF"); if( H.Grid() != t.Grid() || t.Grid() != A.Grid() ) LogicError("{H,t,A} must be distributed over the same grid"); // TODO: Proper dimension checks if( t.Height() != H.DiagonalLength(offset) ) LogicError("t must be the same length as H's offset diag"); if( !t.AlignedWithDiagonal( H, offset ) ) LogicError("t must be aligned with H's offset diagonal"); #endif const Grid& g = H.Grid(); DistMatrix<F> HTL(g), HTR(g), H00(g), H01(g), H02(g), HPan(g), HPanCopy(g), HBL(g), HBR(g), H10(g), H11(g), H12(g), H20(g), H21(g), H22(g); DistMatrix<F> AL(g), AR(g), A0(g), A1(g), A2(g); DistMatrix<F,MD,STAR> tT(g), t0(g), tB(g), t1(g), t2(g); DistMatrix<F,VC, STAR> HPan_VC_STAR(g); DistMatrix<F,MR, STAR> HPan_MR_STAR(g); DistMatrix<F,STAR,STAR> t1_STAR_STAR(g); DistMatrix<F,STAR,STAR> SInv_STAR_STAR(g); DistMatrix<F,STAR,MC > ZAdj_STAR_MC(g); DistMatrix<F,STAR,VC > ZAdj_STAR_VC(g); LockedPartitionDownOffsetDiagonal ( offset, H, HTL, HTR, HBL, HBR, 0 ); LockedPartitionDown ( t, tT, tB, 0 ); PartitionRight( A, AL, AR, 0 ); while( HTL.Height() < H.Height() && HTL.Width() < H.Width() ) { LockedRepartitionDownDiagonal ( HTL, /**/ HTR, H00, /**/ H01, H02, /*************/ /******************/ /**/ H10, /**/ H11, H12, HBL, /**/ HBR, H20, /**/ H21, H22 ); LockedRepartitionDown ( tT, t0, /**/ /**/ t1, tB, t2 ); RepartitionRight ( AL, /**/ AR, A0, /**/ A1, A2, H11.Height() ); LockedView2x1( HPan, H11, H21 ); HPan_MR_STAR.AlignWith( AR ); ZAdj_STAR_MC.AlignWith( AR ); ZAdj_STAR_VC.AlignWith( AR ); //--------------------------------------------------------------------// HPanCopy = HPan; MakeTriangular( LOWER, HPanCopy ); SetDiagonal( HPanCopy, F(1) ); HPan_VC_STAR = HPanCopy; Zeros( SInv_STAR_STAR, HPan.Width(), HPan.Width() ); Herk ( UPPER, ADJOINT, F(1), HPan_VC_STAR.LockedMatrix(), F(0), SInv_STAR_STAR.Matrix() ); SInv_STAR_STAR.SumOverGrid(); t1_STAR_STAR = t1; FixDiagonal( conjugation, t1_STAR_STAR, SInv_STAR_STAR ); HPan_MR_STAR = HPan_VC_STAR; LocalGemm( ADJOINT, ADJOINT, F(1), HPan_MR_STAR, AR, ZAdj_STAR_MC ); ZAdj_STAR_VC.SumScatterFrom( ZAdj_STAR_MC ); LocalTrsm ( LEFT, UPPER, ADJOINT, NON_UNIT, F(1), SInv_STAR_STAR, ZAdj_STAR_VC ); ZAdj_STAR_MC = ZAdj_STAR_VC; LocalGemm ( ADJOINT, ADJOINT, F(-1), ZAdj_STAR_MC, HPan_MR_STAR, F(1), AR ); //--------------------------------------------------------------------// SlideLockedPartitionDownDiagonal ( HTL, /**/ HTR, H00, H01, /**/ H02, /**/ H10, H11, /**/ H12, /*************/ /******************/ HBL, /**/ HBR, H20, H21, /**/ H22 ); SlideLockedPartitionDown ( tT, t0, t1, /**/ /**/ tB, t2 ); SlidePartitionRight ( AL, /**/ AR, A0, A1, /**/ A2 ); } }
void content() { // start render to tex1 pass glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo1); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // clear FBO glUseProgram(0); scene(); // end of render to tex1 pass // start render tex1 to tex2 pass glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo2); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glDepthMask(GL_FALSE); // disable writting to depth buffer if(USE_GREY_FILTER) glUseProgram(greyFilter); // use grey filter else glUseProgram(0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(-1, 1, -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, img1); glEnable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2i(-1,-1); glTexCoord2f(1, 0); glVertex2i( 1,-1); glTexCoord2f(1, 1); glVertex2i( 1, 1); glTexCoord2f(0, 1); glVertex2i(-1, 1); glEnd(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_TRUE); scene(); // draw again with only depth info glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glPushMatrix(); AL(theta, radius); // compute head window coordinate // Al's head is about (0,1,0) world coordinate // NDC = proj ( [PJ][MV](head) ) double winx, winy, winz; double lower_x, lower_y, lower_z; double origin_x, origin_y, origin_z; double front_x, front_y, front_z; double mv[16], proj[16]; int viewport[4]; glGetDoublev(GL_MODELVIEW_MATRIX, mv); glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetIntegerv(GL_VIEWPORT, viewport); gluProject(0, 1.0, 0, mv, proj, viewport, &winx, &winy, &winz); gluProject(0, 0.3, 0, mv, proj, viewport, &lower_x, &lower_y, &lower_z); gluProject(0, 0, 0, mv, proj, viewport, &origin_x, &origin_y, &origin_z); gluProject(1, 0, 0, mv, proj, viewport, &front_x, &front_y, &front_z); Vec3 v = Vec3(front_x - origin_x, front_y - origin_y, front_z - origin_z); glMatrixMode (GL_PROJECTION); glPopMatrix(); glMatrixMode (GL_MODELVIEW); glPopMatrix(); glPopMatrix(); // end of render tex1 to tex2 pass if(USE_MOSAIC_FILTER) { glUseProgram(mosaicFilter); glUniform1f(glGetUniformLocation(mosaicFilter, "gran"), 80.0); float head[2] = {winx, (winy + lower_y) / 2.0}; glUniform2fv(glGetUniformLocation(mosaicFilter, "center"), 1, head); float radius = (winy - lower_y) / 2.0; glUniform1f(glGetUniformLocation(mosaicFilter, "radius"), radius); //cout << v << endl; } else glUseProgram(0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // use FBOs for texture glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(-1, 1, -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, img2); glEnable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2i(-1,-1); glTexCoord2f(1, 0); glVertex2i( 1,-1); glTexCoord2f(1, 1); glVertex2i( 1, 1); glTexCoord2f(0, 1); glVertex2i(-1, 1); glEnd(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); // end of using FBOs for texture*/ overlay(); glutSwapBuffers(); }