@@ -62,29 +62,31 @@ struct TestExternalFunctionLocal : public TestBase<4, 1, 3, TestExternalFunction
6262 int start = ((N - 1 ) / nThreads + 1 ) * omp_get_thread_num ();
6363 int end = std::min (N, ((N - 1 ) / nThreads + 1 ) * (omp_get_thread_num () + 1 ));
6464
65- for (int i = start; i < end; ++i) {
66- Base::job1 (i, in, jobResults[i]);
67- }
65+ if (start < end) { // avoid external functions with empty data
66+ for (int i = start; i < end; ++i) {
67+ Base::job1 (i, in, jobResults[i]);
68+ }
6869
69- codi::ExternalFunctionHelper<T>* eh = new codi::ExternalFunctionHelper<T>(true );
70- for (int i = start; i < end; ++i) {
71- eh->addInput (jobResults[i]);
72- }
70+ codi::ExternalFunctionHelper<T>* eh = new codi::ExternalFunctionHelper<T>(true );
71+ for (int i = start; i < end; ++i) {
72+ eh->addInput (jobResults[i]);
73+ }
7374
74- for (int i = start; i < end; ++i) {
75- eh->addOutput (intermediate[i]);
76- }
75+ for (int i = start; i < end; ++i) {
76+ eh->addOutput (intermediate[i]);
77+ }
7778
78- eh->callPrimalFuncWithADType (TestExternalFunctionLocal::primal<T>, &jobResults[start], end - start,
79- &intermediate[start], end - start, nullptr );
79+ eh->callPrimalFuncWithADType (TestExternalFunctionLocal::primal<T>, &jobResults[start], end - start,
80+ &intermediate[start], end - start, nullptr );
8081
81- eh->addToTape (TestExternalFunctionLocal::reverse);
82+ eh->addToTape (TestExternalFunctionLocal::reverse);
8283
83- for (int i = start; i < end; ++i) {
84- jobResults[i] = cos (exp (intermediate[i]));
85- }
84+ for (int i = start; i < end; ++i) {
85+ jobResults[i] = cos (exp (intermediate[i]));
86+ }
8687
87- delete eh;
88+ delete eh;
89+ }
8890 }
8991 OPDI_END_PARALLEL
9092
0 commit comments