#! /usr/bin/perl #/*@@ # @routine create_schedule_code # @date Fri Jan 8 1999 # @author Gabrielle Allen # @desc # Creates the rfr code from the thorn # schedule.ccl files # @enddesc # @calls # @calledby # @history # @endhistory #@@*/ sub create_schedule_code { local($dir,$n_thorns,@rest) = @_; local($thorn); local(@rfr_file); local(@indata,$implementation); local($schedule_wrappers, $wrapper_files); local(%schedule_ordering); local(@schedule_data); local(@retschedule_data); %thorns = @rest[0..2*$n_thorns-1]; %interface_database = @rest[2*$n_thorns..$#rest]; # Loop though each thorn's schedule file foreach $thorn (keys %thorns) { if ($CST_debug) { print "DEBUG: --> $thorn\n"; } $implementation = $interface_database{"\U$thorn\E IMPLEMENTS"}; # Private groups for thorn $privategroups = $interface_database{"\U$thorn\E PRIVATE GROUPS"}; $thorn_rfr = $thorn."_rfr"; $thorn_startup = $thorn."_startup"; open (OUTRFR, ">$dir/Schedule/$thorn_rfr".".c") || die "Cannot open $thorn_rfr".".c"; open (OUTSTART, ">$dir/Schedule/$thorn_startup".".c") || die "Cannot open $thorn_startup".".c"; $header = &write_rfr_header($thorn,$thorn_rfr); print OUTRFR $header; &write_startup_header($thorn,$thorn_startup,OUTSTART); # Read all the data in the schedule file @indata = &read_file("$thorns{$thorn}/schedule.ccl"); # Parse the data and create rfr and startup subroutines ($proto,$out,$wrapper_files, @retscheduledata) = &parse_schedule_ccl(1,$privategroups,$thorn,$implementation,"rfr",@indata); print OUTRFR $proto; print OUTRFR $out; $rfr_files .= " $thorn_rfr"; $startup_files .= " $thorn_startup"; push(@schedule_data, @retscheduledata); ($proto,$out,$schedule_wrappers) = &parse_schedule_ccl(2,$privategroups,$thorn,$implementation,"startup",@indata); print OUTSTART $proto; print OUTSTART $out; # The footer for the thorn RFR routine print OUTRFR " }\n}\n"; print OUTSTART " }\n}\n"; close OUTRFR; close OUTSTART; } %schedule_ordering = @schedule_data; $schedule_ordering{":THORNS:"} = join(" ", keys %thorns); $schedule_ordering{":ROUTINES:"} = ""; foreach $thorn (keys %thorns) { foreach $routine (split(" ", $schedule_ordering{"\U$thorn"})) { $schedule_ordering{":ROUTINES:"} .= "$routine "; } } return ($wrapper_files,$rfr_files,$startup_files, %schedule_ordering); } sub write_rfr_header { local($thorn,$routine) = @_; local($header); # The header for the thorn RFR routine $header = "#define THORN_IS_$thorn\n"; $header .= "#include \n"; $header .= "#include \"cctk.h\"\n"; $header .= "#include \"cctk_Flesh.h\"\n"; $header .= "#include \"cctk_Comm.h\"\n"; $header .= "/* FIXME - remove when ActiveThorns does not need this */\n"; $header .= "#include \"SKBinTree.h\"\n\n"; $header .= "#include \"cctk_ActiveThorns.h\"\n"; $header .= "#include \"cctk_Groups.h\"\n"; $header .= "#include \"cctk_GroupsOnGH.h\"\n"; $header .= "#include \"rfrConstants.h\"\n"; $header .= "#include \"cctk_parameters.h\"\n"; $header .= "#include \"cctk_arguments.h\"\n"; $header .= "\n"; $header .= "void $routine (cGH *GH)\n"; $header .= "{\n"; $header .= " DECLARE_CCTK_PARAMETERS\n"; $header .= " int index;\n\n"; $header .= "\n"; $header .= " if(CCTK_IsThornActive(\"$thorn\"))\n"; $header .= " {\n\n"; return $header; } sub write_startup_header { local($thorn,$routine,$out) = @_; # The header for the thorn STARTUP routine print OUTSTART "#define THORN_IS_$thorn\n"; print OUTSTART "#include \n"; print OUTSTART "#include \"cctk.h\"\n"; print OUTSTART "#include \"cctk_Flesh.h\"\n"; print OUTSTART "/* FIXME - remove when ActiveThorns does not need this */\n"; print OUTSTART "#include \"SKBinTree.h\"\n\n"; print OUTSTART "#include \"cctk_ActiveThorns.h\"\n"; print OUTSTART "#include \"rfrConstants.h\"\n"; print OUTSTART "#include \"cctk_parameters.h\"\n"; print OUTSTART "\n"; print OUTSTART "void $routine ()\n"; print OUTSTART "{\n"; print OUTSTART " DECLARE_CCTK_PARAMETERS\n"; print OUTSTART "\n"; print OUTSTART " if(CCTK_IsThornActive(\"$thorn\"))\n"; print OUTSTART " {\n\n"; } sub create_RegisterRFR { local ($dir,$n_rfrfiles, @rest) = @_; local ($rfr_calls, $rfr_order_calls, $rfr_order_prototypes, $outfile); local(@sorted_routines); local($routine); local($order, %order); if($n_rfrfiles == 0) { @rfr_files = (); %schedule_data = @rest; } else { @rfr_files = @rest[0..$n_rfrfiles-1]; %schedule_data = @rest[$n_rfrfiles..$#rest]; } $outfile = "$dir/Schedule/Cactus_RegisterRFR.c"; open (OUT, ">$outfile") || die "Cannot open $outfile"; $rfr_calls = ""; $rfr_order_calls = ""; $rfr_order_prototypes = ""; # Sort the rfr routines if ($CST_debug) { print "DEBUG: Ordering RFR routines\n"; } @sorted_routines = &OrderList("Scheduling error", ":ROUTINES:", %schedule_data); $order = 1; foreach $routine (@sorted_routines) { if ($CST_debug) { print "DEBUG: --> $routine\n"; } if($routine) { $rfr_order_prototypes .= "void $routine(cGH *);\n"; $rfr_order_calls .= " rfrRegisterOrderNumber($routine, $order);\n"; $order++; } } foreach $file (@rfr_files) { $rfr_calls = "$rfr_calls ".$file."(data);\n"; } print OUT <$outfile") || die "Cannot open $outfile"; $startup_calls = ""; foreach $file (@startup_routines) { $startup_calls = "$startup_calls ".$file."();\n"; } print OUT </build/bindings/Scheduler/ ) # @enddesc # @calls # @calledby # @history # # @endhistory #@@*/ sub fortran_wrapper { local($thorn,$routine) = @_; local($wrapper,$ROUTINE,$file); $THORN_C2F = "\U$thorn"."_C2F"; $THORN_C2F_PROTO = "\U$thorn"."_C2F_PROTO"; $wrapper = "$routine"."_wrapper"; $file = "$routine"."_wrapper".".c"; open(FILE, ">$file") || die("Can't open $file\n"); print FILE<