If a mac has two cores and has been so programmed, then an appropriately written c code make good use of both processors? Right.
For example if
For (i = 0; i < 10; i+= 2)
a(i) = b(i);
a(i+1) = b(i+ 1);
The assignments in the for statement can be done in parallel since neither line depends on the other, right?
So how do I get this code to run each if statement in parallel.
while ( ( (laserfile1 = readdir(ld)) != NULL) && ( (laserfile2 = readdir(ld)) != NULL ) )
{
if ( strstr(laserfile1->d_name, "fits") != NULL)
{
printf("%s\n", laserfile1->d_name);
//shift
strcpy (infile1, laserdirectory);
strcat (infile1, laserfile1->d_name);
strcpy (outfile1, laserdirectory);
strcat (outfile1, laserfile1->d_name);
shift (infile1, outfile1);
//cosmic rays
strcpy(cmd1, codedirectory);
strcat(cmd1, "cosmicrays input = ");
strcat(cmd1, laserdirectory);
strcat(cmd1, laserfile1->d_name);
strcat(cmd1, "[0] ");
strcat(cmd1, "output = ");
strcat(cmd1, laserdirectory);
strcat(cmd1, laserfile1->d_name);
strcat(cmd1, "[0] ");
system(cmd1);
//subtract darks
//findlaserspots
strcpy (spotfile1, psfdirectory);
strcat (spotfile1, "S");
strcat (spotfile1, laserfile1->d_name);
findlaserspots (infile1, spotfile1);
//make psf images
strcpy (outfile1, psfdirectory);
strcat (outfile1, laserfile1->d_name);
makelaserpsf (spotfile1, infile1, outfile1);
centroidpsfs(spotfile1, outfile1);
}
if ( strstr(laserfile2->d_name, "fits") != NULL)
{
printf("%s\n", laserfile2->d_name);
//shift
strcpy (infile2, laserdirectory);
strcat (infile2, laserfile2->d_name);
strcpy (outfile2, laserdirectory);
strcat (outfile2, laserfile2->d_name);
shift (infile2, outfile2);
//cosmic rays
strcpy(cmd2, codedirectory);
strcat(cmd2, "cosmicrays input = ");
strcat(cmd2, laserdirectory);
strcat(cmd2, laserfile2->d_name);
strcat(cmd2, "[0] ");
strcat(cmd2, "output = ");
strcat(cmd2, laserdirectory);
strcat(cmd2, laserfile2->d_name);
strcat(cmd2, "[0] ");
system(cmd2);
//subtract darks
//findlaserspots
strcpy (spotfile2, psfdirectory);
strcat (spotfile2, "S");
strcat (spotfile2, laserfile2->d_name);
findlaserspots (infile2, spotfile2);
//make psf images
strcpy (outfile2, psfdirectory);
strcat (outfile2, laserfile2->d_name);
makelaserpsf (spotfile2, infile2, outfile2);
centroidpsfs(spotfile2, outfile2);
}
}
Thanks
For example if
For (i = 0; i < 10; i+= 2)
a(i) = b(i);
a(i+1) = b(i+ 1);
The assignments in the for statement can be done in parallel since neither line depends on the other, right?
So how do I get this code to run each if statement in parallel.
while ( ( (laserfile1 = readdir(ld)) != NULL) && ( (laserfile2 = readdir(ld)) != NULL ) )
{
if ( strstr(laserfile1->d_name, "fits") != NULL)
{
printf("%s\n", laserfile1->d_name);
//shift
strcpy (infile1, laserdirectory);
strcat (infile1, laserfile1->d_name);
strcpy (outfile1, laserdirectory);
strcat (outfile1, laserfile1->d_name);
shift (infile1, outfile1);
//cosmic rays
strcpy(cmd1, codedirectory);
strcat(cmd1, "cosmicrays input = ");
strcat(cmd1, laserdirectory);
strcat(cmd1, laserfile1->d_name);
strcat(cmd1, "[0] ");
strcat(cmd1, "output = ");
strcat(cmd1, laserdirectory);
strcat(cmd1, laserfile1->d_name);
strcat(cmd1, "[0] ");
system(cmd1);
//subtract darks
//findlaserspots
strcpy (spotfile1, psfdirectory);
strcat (spotfile1, "S");
strcat (spotfile1, laserfile1->d_name);
findlaserspots (infile1, spotfile1);
//make psf images
strcpy (outfile1, psfdirectory);
strcat (outfile1, laserfile1->d_name);
makelaserpsf (spotfile1, infile1, outfile1);
centroidpsfs(spotfile1, outfile1);
}
if ( strstr(laserfile2->d_name, "fits") != NULL)
{
printf("%s\n", laserfile2->d_name);
//shift
strcpy (infile2, laserdirectory);
strcat (infile2, laserfile2->d_name);
strcpy (outfile2, laserdirectory);
strcat (outfile2, laserfile2->d_name);
shift (infile2, outfile2);
//cosmic rays
strcpy(cmd2, codedirectory);
strcat(cmd2, "cosmicrays input = ");
strcat(cmd2, laserdirectory);
strcat(cmd2, laserfile2->d_name);
strcat(cmd2, "[0] ");
strcat(cmd2, "output = ");
strcat(cmd2, laserdirectory);
strcat(cmd2, laserfile2->d_name);
strcat(cmd2, "[0] ");
system(cmd2);
//subtract darks
//findlaserspots
strcpy (spotfile2, psfdirectory);
strcat (spotfile2, "S");
strcat (spotfile2, laserfile2->d_name);
findlaserspots (infile2, spotfile2);
//make psf images
strcpy (outfile2, psfdirectory);
strcat (outfile2, laserfile2->d_name);
makelaserpsf (spotfile2, infile2, outfile2);
centroidpsfs(spotfile2, outfile2);
}
}
Thanks