int main(int argc, char *argv[]) { //INITILIZATION MPIInit(argc, argv); PTHREADInit(argc, argv); if (rank == 0) gettimeofday(&tvalBefore, NULL); //READFILE int fileArray[1000]; for (int ix = 0; ix < 10; ix++) { int file = fileArray[ix]; //Open new file with suffix ix openWriteFile((char *)nameGenerate("dummy", ix).c_str(), &file); //Print 0 to each file int num = 0; if (rank == 0) { lseek(file, 0, SEEK_SET); write(file, &num, sizeof(int)); } //Generate lock parameter struct flock lock; memset(&lock, 0, sizeof(lock)); MPIBarrier(); //Lock file lock.l_type = F_WRLCK; fcntl(file,F_SETLKW, &lock); //Read from file num lseek(file, 0, SEEK_SET); read(file, &num, sizeof(int)); num++; //Overwrite num+1 to file lseek(file, 0, SEEK_SET); write(file, &num,sizeof(int)); printf("(Process %2d) ix = %4d | num = %4d\n",rank, ix, num); //Unlock the file lock.l_type = F_UNLCK; fcntl(file, F_SETLK, &lock); } //FINALIZATION MPIBarrier(); if (rank == 0) { gettimeofday(&tvalAfter, NULL); printDiff(tvalBefore, tvalAfter); } MPIFinalize(); PTHREADFinalize(); return 0; }
int main( int argc, char **argv ) { clock_t t0 = StartTiming(); /* ---------- */ /* Parameters */ /* ---------- */ MPIInit( argc, argv ); if( !gArgs.SetCmdLine( argc, argv ) || !gArgs.GetRanges() ) { MPIExit(); exit( 42 ); } /* ------------ */ /* Initial data */ /* ------------ */ if( !LayerCat( vL, gArgs.tempdir, gArgs.cachedir, gArgs.zolo, gArgs.zohi, false ) ) { MPIExit(); exit( 42 ); } InitTables( gArgs.zilo, gArgs.zihi ); { CLoadPoints *LP = new CLoadPoints; LP->Load( gArgs.tempdir, gArgs.cachedir ); delete LP; } /* ----- */ /* Solve */ /* ----- */ printf( "\n---- Solve ----\n" ); SetSolveParams( gArgs.regtype, gArgs.Wr, gArgs.Etol ); XArray Xevn, Xodd; if( !strcmp( gArgs.mode, "A2A" ) ) { Xevn.Load( gArgs.prior ); if( gArgs.untwist ) UntwistAffines( Xevn ); Xodd.Resize( 6 ); Solve( Xevn, Xodd, gArgs.iters ); } else if( !strcmp( gArgs.mode, "A2H" ) ) { Xevn.Resize( 8 ); { // limit A lifetime XArray *A = new XArray; A->Load( gArgs.prior ); if( gArgs.untwist ) UntwistAffines( *A ); Solve( *A, Xevn, 1 ); delete A; } Xodd.Resize( 8 ); Solve( Xevn, Xodd, gArgs.iters ); } else if( !strcmp( gArgs.mode, "H2H" ) ) { Xevn.Load( gArgs.prior ); Xodd.Resize( 8 ); Solve( Xevn, Xodd, gArgs.iters ); } else if( !strcmp( gArgs.mode, "eval" ) ) { Xevn.Load( gArgs.prior ); if( gArgs.untwist ) UntwistAffines( Xevn ); gArgs.iters = 0; } else { // split Xevn.Load( gArgs.prior ); gArgs.iters = 0; } const XArray& Xfinal = ((gArgs.iters & 1) ? Xodd : Xevn); /* ----------- */ /* Postprocess */ /* ----------- */ if( gArgs.mode[0] == 's' ) { Split S( Xfinal, gArgs.splitmin ); S.Run(); } else { Evaluate( Xfinal ); if( gArgs.mode[0] != 'e' ) Xfinal.Save(); } /* ------- */ /* Cleanup */ /* ------- */ if( !wkid ) { printf( "\n" ); StopTiming( stdout, "Lsq", t0 ); } MPIExit(); VMStats( stdout ); return 0; }