@@ -693,13 +693,31 @@ KMPC_GENERIC_P_2I(ll_make_kmpc_cancellationpoint, KMPC_API_CANCELLATIONPOINT,
693693
694694/* arglist is 1 containing the uplevel pointer */
695695int
696- ll_make_kmpc_fork_call(SPTR sptr, int argc, int *arglist, RegionType rt)
696+ ll_make_kmpc_fork_call(SPTR sptr, int argc, int *arglist, RegionType rt, int ngangs_ili )
697697{
698- int argili, args[4 ];
699- DTYPE arg_types[] = {DT_CPTR, DT_INT, DT_CPTR, DT_NONE};
698+ int argili, args[5 ];
699+ DTYPE arg_types[] = {DT_CPTR, DT_INT, DT_CPTR, DT_NONE, DT_NONE };
700700 arg_types[3 ] = DT_CPTR;
701- args[3 ] = gen_null_arg (); /* ident */
702- args[2 ] = ad_icon (argc);
701+
702+ int call_pgi_kmpc_fork_call = (rt == OPENACC);
703+ call_pgi_kmpc_fork_call = 0 ;
704+
705+ if (call_pgi_kmpc_fork_call) {
706+ // In case we call pgi_kmpc_fork_call, we must also pass in the
707+ // number of gangs. Because the function takes varargs, the num_gangs
708+ // argument needs to appear before end of argument list - thus shift
709+ // arguments over to make room for num_gangs argument.
710+ arg_types[4 ] = arg_types[3 ];
711+ arg_types[3 ] = arg_types[2 ];
712+ arg_types[2 ] = DT_INT; // num_gangs is integer argument
713+ args[4 ] = gen_null_arg ();
714+ args[3 ] = ad_icon (argc);
715+ args[2 ] = ngangs_ili;
716+ } else {
717+ args[3 ] = gen_null_arg (); /* ident */
718+ args[2 ] = ad_icon (argc);
719+ }
720+
703721 args[1 ] = ad1ili (IL_ACON, get_acon (sptr, 0 ));
704722 args[0 ] = *arglist;
705723 return mk_kmpc_api_call (KMPC_API_FORK_CALL, 4 , arg_types, args);
0 commit comments