gridlab-d / gridlab-d

Source Code for GridLAB-D
Other
161 stars 110 forks source link

Error running GridLabD on MacOS Sonoma 14.7 #1474

Closed abhyshr closed 2 weeks ago

abhyshr commented 2 weeks ago

Initial Checklist prior to submitting the issue. Check the bellow boxes to the best of your knowledge:

I am getting an error running GridLabD on MacOS Sonoma 14.7. The compiler used is Clang

bash-3.2$ cc --version
Apple clang version 16.0.0 (clang-1600.0.26.4)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

GridLabD was built in Debug version

cmake -DCMAKE_INSTALL_PREFIX=<install_lib> -DCMAKE_BUILD_TYPE=Debug ..

On running --version, I get the following error

bash-3.2$ gridlabd --version

GridLAB-D 5.2.0-19880 (281cf249:feature/730:Modified) 64-bit MACOSX RELEASE
WARNING  [INIT] : unable to set thread policy: No such process

Backtrace shows the error is in glcore/module.cpp

#elif defined MACOSX        // TODO set mp affinity                                                                                                                           
if ( global_threadcount==1 )        {                
policy.affinity_tag = cpu;                
if (thread_policy_set(mach_thread_self(), THREAD_AFFINITY_POLICY, reinterpret_cast<thread_policy_t>(&policy), THREAD_AFFINITY_POLICY_COUNT) != KERN_SUCCESS )      
output_warning("unable to set thread policy: %s", strerror(errno));        
}

When running autotests (I tried tests from generators/autotests and powerflow/autotests, the test crashes with a segmentation fault at the same location in the code. Here's the fault location and the backtrace

bash-3.2$ pwd
/Users/abhy245/gridlabd-dir/gridlab-d/powerflow/autotest/test
bash-3.2$ lldb -- gridlabd ../test_powerflow_exercise_4_1_3.glm
(lldb) target create "gridlabd"
Current executable set to '/Users/abhy245/gridlabd-dir/gridlab-d/install-scl/bin/gridlabd' (arm64).
(lldb) settings set -- target.run-args  "../test_powerflow_exercise_4_1_3.glm"
(lldb) r
Process 55663 launched: '/Users/abhy245/gridlabd-dir/gridlab-d/install-scl/bin/gridlabd' (arm64)
Process 55663 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x736f6c6320676ebd)
    frame #0: 0x0000000100010434 gridlabd`_set_rankx(obj=0x736f6c6320676e69, rank=0, first=0x00000001000f9110) at object.cpp:1287:21
   1284             output_error("%s: set_rank failed, parent loopback has occurred", object_name(first, tmp, sizeof(tmp)));
   1285             return -1;
   1286         }
-> 1287         if ( rank >= obj->rank )
   1288         {
   1289             if ( obj->flags & OF_RERANK )
   1290             {
Target 0: (gridlabd) stopped.

Backtrace

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x736f6c6320676ebd)
  * frame #0: 0x0000000100010434 gridlabd`_set_rankx(obj=0x736f6c6320676e69, rank=0, first=0x00000001000f9110) at object.cpp:1287:21
    frame #1: 0x000000010000acf8 gridlabd`set_rank(obj=0x00000001000f9110, rank=0, first=0x0000000000000000) at object.cpp:1308:33
    frame #2: 0x000000010000ae04 gridlabd`object_set_parent(obj=0x000000015ae04850, parent=0x00000001000f9110) at object.cpp:1346:10
    frame #3: 0x0000000100ac13fc tape.dylib`gl_set_parent(obj=0x000000015ae04850, parent=0x00000001000f9110) at gridlabd.h:505:10
    frame #4: 0x000000010124306c powerflow.dylib`create_triplex_line_configuration(obj=0x000000016fdf89d8, parent=0x00000001000f9110) at triplex_line_configuration.cpp:91:4
    frame #5: 0x0000000100074d20 gridlabd`object_block(_p="\n\tname triplex_line_configuration_1;\n\tconductor_1 object triplex_line_conductor {\n\tresistance 0.97;\n\tgeometric_mean_radius 0.0111;\n\t};\n\tconductor_2 object triplex_line_conductor {\n\tresistance 0.97;\n\tgeometric_mean_radius 0.0111;\n\t};\n\tconductor_N object triplex_line_conductor {\n\tresistance 0.97;\n\tgeometric_mean_radius 0.0111;\n\t};\n\tinsulation_thickness 0.08;\n\tdiameter 0.368;\n}\n", parent=0x0000000000000000, subobj=0x0000000000000000) at load.cpp:4579:8
    frame #6: 0x0000000100068354 gridlabd`gridlabd_file(_p="object triplex_line_configuration {\n\tname triplex_line_configuration_1;\n\tconductor_1 object triplex_line_conductor {\n\tresistance 0.97;\n\tgeometric_mean_radius 0.0111;\n\t};\n\tconductor_2 object triplex_line_conductor {\n\tresistance 0.97;\n\tgeometric_mean_radius 0.0111;\n\t};\n\tconductor_N object triplex_line_conductor {\n\tresistance 0.97;\n\tgeometric_mean_radius 0.0111;\n\t};\n\tinsulation_thickness 0.08;\n\tdiameter 0.368;\n}\n") at load.cpp:5816:8
    frame #7: 0x0000000100068c0c gridlabd`loadall_glm_roll(file="../test_powerflow_exercise_4_1_3.glm") at load.cpp:7081:11
    frame #8: 0x0000000100069c38 gridlabd`loadall(file="../test_powerflow_exercise_4_1_3.glm") at load.cpp:7244:17
    frame #9: 0x000000010001d198 gridlabd`cmdarg_load(argc=1, argv=0x000000016fdff3d8) at cmdarg.cpp:1607:11
    frame #10: 0x0000000100098c68 gridlabd`main(argc=2, argv=0x000000016fdff3d0) at main.cpp:182:9
    frame #11: 0x000000019a313154 dyld`start + 2476

@ftuffner @trevorhardy @afisher1 @eranschweitzer

abhyshr commented 2 weeks ago

The fix for this, thank you @ftuffner and @trevorhardy , is to use arch -x86_64 while launching the shell and recompile. @trevorhardy has already documented this fix here.