T* SGMatrix<T>::get_column_sum(T* matrix, int32_t m, int32_t n) { T* colsums=SG_CALLOC(T, m); for (int64_t i=0; i<n; i++) { for (int64_t j=0; j<m; j++) colsums[j]+=matrix[j+i*m]; } return colsums; }
T* SGMatrix<T>::get_row_sum(T* matrix, int32_t m, int32_t n) { T* rowsums=SG_CALLOC(T, n); for (int64_t i=0; i<n; i++) { for (int64_t j=0; j<m; j++) rowsums[i]+=matrix[j+i*m]; } return rowsums; }
double* SGMatrix<T>::compute_eigenvectors(double* matrix, int n, int m) { ASSERT(n == m); char V='V'; char U='U'; int info; int ord=n; int lda=n; double* eigenvalues=SG_CALLOC(float64_t, n+1); // lapack sym matrix eigenvalues+vectors wrap_dsyev(V, U, ord, matrix, lda, eigenvalues, &info); if (info!=0) SG_SERROR("DSYEV failed with code %d\n", info); return eigenvalues; }
/** * @brief syndicate-removexattr entry point * */ int main( int argc, char** argv ) { int rc = 0; struct UG_state* ug = NULL; struct SG_gateway* gateway = NULL; char* path = NULL; char* xattr = NULL; int path_optind = 0; struct tool_opts opts; uint64_t* times = NULL; struct timespec ts_begin; struct timespec ts_end; memset( &opts, 0, sizeof(tool_opts) ); argc = parse_args( argc, argv, &opts ); if( argc < 0 ) { usage( argv[0], "path xattr [xattr...]" ); md_common_usage(); exit(1); } // setup... ug = UG_init( argc, argv ); if( ug == NULL ) { SG_error("%s", "UG_init failed\n" ); exit(1); } gateway = UG_state_gateway( ug ); // get the directory path path_optind = SG_gateway_first_arg_optind( gateway ); if( path_optind + 1 >= argc ) { usage( argv[0], "path xattr [xattr...]" ); md_common_usage(); UG_shutdown( ug ); exit(1); } if( opts.benchmark ) { times = SG_CALLOC( uint64_t, argc - path_optind + 1 ); if( times == NULL ) { UG_shutdown( ug ); SG_error("%s", "Out of memory\n"); exit(1); } } path = argv[path_optind]; for( int i = path_optind + 1; i < argc; i++ ) { xattr = argv[ i ]; // load up... clock_gettime( CLOCK_MONOTONIC, &ts_begin ); rc = UG_removexattr( ug, path, xattr ); if( rc < 0 ) { fprintf(stderr, "Failed to removexattr '%s' '%s': %s\n", path, xattr, strerror(abs(rc)) ); rc = 1; break; } clock_gettime( CLOCK_MONOTONIC, &ts_end ); if( times != NULL ) { times[i - path_optind] = md_timespec_diff( &ts_end, &ts_begin ); } } if( times != NULL ) { printf("@@@@@"); for( int i = path_optind; i < argc - 1; i++ ) { printf("%" PRIu64 ",", times[i - path_optind] ); } printf("%" PRIu64 "@@@@@\n", times[argc - 1 - path_optind] ); SG_safe_free( times ); } UG_shutdown( ug ); exit(rc); }
/** * @brief syndicate-get entry point * */ int main( int argc, char** argv ) { int rc = 0; struct UG_state* ug = NULL; struct SG_gateway* gateway = NULL; char* path = NULL; int path_optind = 0; char* file_path = NULL; int fd = 0; char* buf = NULL; ssize_t nr = 0; ssize_t total = 0; UG_handle_t* fh = NULL; int t = 0; struct timespec ts_begin; struct timespec ts_end; int64_t* times = NULL; mode_t um = umask(0); umask( um ); struct tool_opts opts; memset( &opts, 0, sizeof(tool_opts) ); argc = parse_args( argc, argv, &opts ); if( argc < 0 ) { usage( argv[0], "syndicate_file local_file [syndicate_file local_file...]" ); md_common_usage(); exit(1); } // setup... ug = UG_init( argc, argv ); if( ug == NULL ) { SG_error("%s", "UG_init failed\n" ); exit(1); } gateway = UG_state_gateway( ug ); // get the path... path_optind = SG_gateway_first_arg_optind( gateway ); if( path_optind == argc || ((argc - path_optind) % 2) != 0 ) { usage( argv[0], "syndicate_file local_file [syndicate_file local_file]" ); UG_shutdown( ug ); exit(1); } if( opts.benchmark ) { times = SG_CALLOC( int64_t, (argc - path_optind) / 2 + 1 ); if( times == NULL ) { UG_shutdown( ug ); SG_error("%s", "Out of memory\n"); exit(1); } } buf = SG_CALLOC( char, BUF_SIZE ); if( buf == NULL ) { UG_shutdown( ug ); SG_error("%s", "Out of memory\n"); exit(1); } for( int i = path_optind; i < argc; i += 2 ) { total = 0; // get the syndicate path... path = argv[i]; // get the file path... file_path = argv[i+1]; // open the file... fd = open( file_path, O_CREAT | O_EXCL | O_WRONLY, 0600 ); if( fd < 0 ) { rc = -errno; fprintf(stderr, "Failed to open '%s': %s\n", file_path, strerror(-rc)); rc = 1; goto get_end; } // try to open fh = UG_open( ug, path, O_RDONLY, &rc ); if( rc != 0 ) { fprintf(stderr, "Failed to open '%s': %d %s\n", path, rc, strerror( abs(rc) ) ); rc = 1; goto get_end; } clock_gettime( CLOCK_MONOTONIC, &ts_begin ); while( 1 ) { nr = UG_read( ug, buf, BUF_SIZE, fh ); if( nr == 0 ) { break; } if( nr < 0 ) { rc = nr; fprintf(stderr, "Failed to read '%s': %s\n", path, strerror(abs(rc))); break; } rc = write( fd, buf, nr ); if( rc < 0 ) { rc = -errno; fprintf(stderr, "Failed to write '%s': %d %s\n", file_path, rc, strerror(abs(rc))); break; } total += nr; } close( fd ); if( rc < 0 ) { rc = 1; goto get_end; } clock_gettime( CLOCK_MONOTONIC, &ts_end ); // close rc = UG_close( ug, fh ); if( rc != 0 ) { fprintf(stderr, "Failed to close '%s': %d %s\n", path, rc, strerror( abs(rc) ) ); rc = 1; goto get_end; } if( times != NULL ) { printf("\n%ld.%ld - %ld.%ld = %ld\n", ts_end.tv_sec, ts_end.tv_nsec, ts_begin.tv_sec, ts_begin.tv_nsec, md_timespec_diff_ms( &ts_end, &ts_begin )); times[t] = md_timespec_diff_ms( &ts_end, &ts_begin ); t++; } SG_debug("Read %zd bytes for %s\n", total, path ); } get_end: UG_shutdown( ug ); SG_safe_free( buf ); if( times != NULL ) { printf("@@@@@"); for( int i = 0; i < t - 1; i++ ) { printf("%" PRId64 ",", times[i] ); } printf("%" PRId64 "@@@@@\n", times[t-1] ); SG_safe_free( times ); } if( rc != 0 ) { exit(1); } else { exit(0); } }