@@ -84,13 +84,32 @@ impl Plotter {
8484 if !task. quiet {
8585 println ! (
8686 "CPU: {} [using {} of {} cores{}{}]" ,
87- cpu_name, task. cpu_threads, cores, if simd_ext != "" { " + " } else { "" } , simd_ext
87+ cpu_name,
88+ task. cpu_threads,
89+ cores,
90+ if simd_ext != "" { " + " } else { "" } ,
91+ simd_ext
8892 ) ;
8993 }
9094
95+ let file = Path :: new ( & task. output_path ) . join ( format ! (
96+ "{}_{}_{}" ,
97+ task. numeric_id, task. start_nonce, task. nonces
98+ ) ) ;
99+
100+ if !file. parent ( ) . unwrap ( ) . exists ( ) {
101+ println ! (
102+ "Error: specified target path does not exist, path={}" ,
103+ & task. output_path
104+ ) ;
105+ println ! ( "Shutting down..." ) ;
106+ return ;
107+ }
108+
91109 // use all avaiblable disk space if nonce parameter has been omitted
110+ let free_disk_space = free_disk_space ( & task. output_path ) ;
92111 if task. nonces == 0 {
93- task. nonces = free_disk_space ( & task . output_path ) / NONCE_SIZE ;
112+ task. nonces = free_disk_space / NONCE_SIZE ;
94113 }
95114
96115 // align number of nonces with sector size if direct i/o
@@ -108,8 +127,22 @@ impl Plotter {
108127
109128 let plotsize = task. nonces * NONCE_SIZE ;
110129
130+ // check available disk space
131+ if free_disk_space < plotsize {
132+ println ! (
133+ "Error: insufficient disk space, MiB_required={}, MiB_available={}" ,
134+ plotsize as f64 / 1024.0 / 1024.0 ,
135+ free_disk_space as f64 / 1024.0 / 1024.0
136+ ) ;
137+ println ! ( "Shutting down..." ) ;
138+ return ;
139+ }
140+
111141 // calculate memory usage
112- let mem = calculate_mem_to_use ( & task, & memory, nonces_per_sector) ;
142+ let mem = match calculate_mem_to_use ( & task, & memory, nonces_per_sector) {
143+ Ok ( x) => x,
144+ Err ( _) => return
145+ } ;
113146
114147 if !task. quiet {
115148 println ! (
@@ -132,11 +165,6 @@ impl Plotter {
132165 ) ;
133166 }
134167
135- let file = Path :: new ( & task. output_path ) . join ( format ! (
136- "{}_{}_{}" ,
137- task. numeric_id, task. start_nonce, task. nonces
138- ) ) ;
139-
140168 if !task. quiet {
141169 println ! ( "Output File: {}\n " , file. display( ) ) ;
142170 }
@@ -218,9 +246,9 @@ impl Plotter {
218246 let task = Arc :: new ( task) ;
219247
220248 // hi bold! might make this optional in future releases.
249+ let thread_pinning = true ;
221250 let mut core_ids: Vec < core_affinity:: CoreId > = Vec :: new ( ) ;
222251
223- let thread_pinning = true ;
224252 if thread_pinning {
225253 core_ids = core_affinity:: get_core_ids ( ) . unwrap ( ) ;
226254 }
@@ -288,9 +316,23 @@ fn calculate_mem_to_use(
288316 task : & PlotterTask ,
289317 memory : & sys_info:: MemInfo ,
290318 nonces_per_sector : u64 ,
291- ) -> u64 {
319+ ) -> Result < u64 , & ' static str > {
292320 let plotsize = task. nonces * NONCE_SIZE ;
293- let mut mem = task. mem . parse :: < Bytes > ( ) . unwrap ( ) . size ( ) as u64 ;
321+
322+ let mut mem = match task. mem . parse :: < Bytes > ( ) {
323+ Ok ( x) => x. size ( ) as u64 ,
324+ Err ( _) => { println ! (
325+ "Error: Can't parse memory limit parameter, input={}" ,
326+ task. mem,
327+ ) ;
328+ println ! ( "\n Please specify a number followed by a unit. If no unit is provided, bytes will be assumed." ) ;
329+ println ! ( "Supported units: B, KiB, MiB, GiB, TiB, PiB, EiB, KB, MB, GB, TB, PB, EB" ) ;
330+ println ! ( "Example: --mem 10GiB\n " ) ;
331+ println ! ( "Shutting down..." ) ;
332+ return Err ( "invalid unit" ) ;
333+ }
334+ } ;
335+
294336 if mem == 0 {
295337 mem = plotsize;
296338 }
@@ -306,7 +348,7 @@ fn calculate_mem_to_use(
306348
307349 // ensure a minimum buffer
308350 mem = max ( mem, num_buffer * NONCE_SIZE * nonces_per_sector) ;
309- mem
351+ Ok ( mem)
310352}
311353
312354fn detect_simd ( ) -> String {
0 commit comments