<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Times New Roman; font-size: 12pt; color: #000000'>Dear Andreas,<div><br></div><div>My OpenMP implementation perform the MP just using pragma directives, so if the -fopenmp flag is not set, the compiler will just ignore these lines and it will perform a single processor build. I checked both builds with gcc. We would be in a different situation if I had used OpenMP API calls. In fact, the #include<omp.h> I included in my patch it is not necessary at all (sorry). This way, the MP or sequential build just depends on the use of the -fopenmp flag.</div><div><br></div><div>Keep in mind that this flag differs between compilares (e.g, -openmp for icc, -mp for openUH, etc.) if you want to bring support for different compilers in the autoconf file.</div><div><br></div><div>Kind regards,</div><div><br></div><div>Diego.<br><br><hr id="zwchr"><b>De: </b>"Andreas Tille" <andreas@an3as.eu><br><b>Para: </b>"Diego Darriba" <ddarriba@udc.es><br><b>CC: </b>"s guindon" <s.guindon@auckland.ac.nz>, "Stephane Guindon" <guindon@stat.auckland.ac.nz>, "Olivier Gascuel" <gascuel@lirmm.fr>, "Jean-Francois Dufayard" <jeanfrancois.dufayard@gmail.com>, "David Posada" <dposada@uvigo.es>, "Debian Med Packaging Team" <debian-med-packaging@lists.alioth.debian.org><br><b>Enviados: </b>Martes, 15 de Febrero 2011 21:25:51<br><b>Asunto: </b>Re: MP patch for PhyML<br><br>Dear Diego,<br><br>I admit I have no experience with MP builds but I wonder whether you<br>should not include the changes into #ifdef USEMP / #else / #endif<br>statements to enable both - single processor and MP builds. Or does the<br>patch work with both and it is just the build option which controls<br>everything?<br><br>Kind regards<br><br> Andreas.<br><br>On Tue, Feb 15, 2011 at 06:58:19PM +0100, Diego Darriba wrote:<br>> Dear Stephan et al,<br>><br>> I send you the patch for the current phyml trunk. I checked the results <br>> with several input data, and I think I solved correctly some <br>> dependencies in the parallelized loops from my computer science point of <br>> view. In the configure.ac it is just necessary to include the *-fopenmp* <br>> flag for compiling (if using gcc compiler). I would modify it, but I <br>> prefer you to do so. That way you can create a conditional Makefile, or <br>> include the flag as a commentary, or whatever.<br>><br>> If the compilation flag is not set, the application will compile with no <br>> error, but it will run as before (i.e, sequentially).<br>><br>> Please, let me know if you have any doubt or any problem.<br>><br>> Kind Regards,<br>><br>> Diego.<br>><br>> El 15/02/11 02:51, Stephane Guindon escribió:<br>>> Dear Andreas,<br>>><br>>> Thank you very much for contributing to PhyML.<br>>> Yes, it makes perfect sense to try and include this functionality<br>>> into the latest release of the program. Please feel free to take<br>>> a look at the most recent version of the sources on our svn server<br>>> (http://code.google.com/p/phyml/source/browse/#svn%2Ftrunk%2Fsrc)<br>>> and let me know how to amend the configure.ac, *.c and *.h file<br>>> in an appropriate manner.<br>>><br>>> Regards,<br>>><br>>> -Stephane-<br>>><br>>> On 15/02/11 03:26, Andreas Tille wrote:<br>>>> Hi PhyML authors,<br>>>><br>>>> when discssing with Diego about a program which uses PhyML he told me<br>>>> about his MP patch which would enable making use of hybrid memory when<br>>>> running PhyML on clusters. I was considering to port this patch to the<br>>>> Debian packaged version where I intended to support two versions of<br>>>> the package: one conventional phylip and one phylip-mp.<br>>>><br>>>> When inspecting the patch I noticed that it was done against an older<br>>>> version of PhyML (20100123). I would consider it a reasonable idea if<br>>>> this patch would be included into the upstream version by just wrapping<br>>>> it into "#ifdef"s properly to enable switching between both versions by<br>>>> simply providing different options to make. If the patch would be taken<br>>>> over into the official PhyML code this would simplify our work as<br>>>> distributor (as well as Diego's work) and it might be of extra value for<br>>>> other users.<br>>>><br>>>> What do you think about this idea?<br>>>><br>>>> Kind regards<br>>>><br>>>> Andreas.<br>>>><br>><br><br>> Index: src/lk.c<br>> ===================================================================<br>> --- src/lk.c (revisi??n: 582)<br>> +++ src/lk.c (copia de trabajo)<br>> @@ -11,8 +11,8 @@<br>> */<br>> <br>> #include "lk.h"<br>> +#include <omp.h><br>> <br>> -<br>> /* int LIM_SCALE; */<br>> /* phydbl LIM_SCALE_VAL; */<br>> /* phydbl BIG; */<br>> @@ -320,8 +320,9 @@<br>> <br>> phydbl Lk(t_tree *tree)<br>> {<br>> - int br;<br>> + int br, site;<br>> int n_patterns;<br>> + phydbl c_lnL;<br>> <br>> tree->old_lnL = tree->c_lnL;<br>> <br>> @@ -349,10 +350,17 @@<br>> <br>> tree->c_lnL = .0;<br>> tree->sum_min_sum_scale = .0;<br>> - For(tree->curr_site,n_patterns)<br>> +<br>> + c_lnL = .0;<br>> + #pragma omp parallel for reduction(+:c_lnL)<br>> + For(site,n_patterns)<br>> {<br>> - if(tree->data->wght[tree->curr_site] > SMALL) Lk_Core(tree->noeud[0]->b[0],tree);<br>> + if(tree->data->wght[site] > SMALL) {<br>> + Lk_Core(tree->noeud[0]->b[0],tree,site);<br>> + c_lnL += tree->c_lnL_sorted[site];<br>> + }<br>> }<br>> + tree->c_lnL = c_lnL;<br>> <br>> /* Qksort(tree->c_lnL_sorted,NULL,0,n_patterns-1); */<br>> <br>> @@ -372,7 +380,8 @@<br>> <br>> phydbl Lk_At_Given_Edge(t_edge *b_fcus, t_tree *tree)<br>> {<br>> - int n_patterns;<br>> + int n_patterns,site;<br>> + phydbl c_lnL;<br>> <br>> n_patterns = tree->n_pattern;<br>> <br>> @@ -396,10 +405,17 @@<br>> <br>> tree->c_lnL = .0;<br>> tree->sum_min_sum_scale = .0;<br>> - For(tree->curr_site,n_patterns)<br>> +<br>> + c_lnL = .0;<br>> + #pragma omp parallel for reduction(+:c_lnL)<br>> + For(site,n_patterns)<br>> {<br>> - if(tree->data->wght[tree->curr_site] > SMALL) Lk_Core(b_fcus,tree);<br>> + if(tree->data->wght[site] > SMALL) {<br>> + Lk_Core(b_fcus,tree,site);<br>> + c_lnL += tree->c_lnL_sorted[site];<br>> + }<br>> }<br>> + tree->c_lnL = c_lnL;<br>> <br>> /* Qksort(tree->c_lnL_sorted,NULL,0,n_patterns-1); */<br>> <br>> @@ -422,7 +438,7 @@<br>> <br>> #ifndef USE_OLD_LK<br>> <br>> -phydbl Lk_Core(t_edge *b, t_tree *tree)<br>> +phydbl Lk_Core(t_edge *b, t_tree *tree, int site)<br>> {<br>> phydbl log_site_lk;<br>> phydbl site_lk_cat, site_lk;<br>> @@ -431,7 +447,7 @@<br>> phydbl max_sum_scale;<br>> phydbl sum;<br>> int ambiguity_check,state;<br>> - int catg,ns,k,l,site;<br>> + int catg,ns,k,l;<br>> int dim1,dim2,dim3;<br>> int *sum_scale_left_cat,*sum_scale_rght_cat;<br>> phydbl multiplier;<br>> @@ -439,6 +455,7 @@<br>> phydbl tmp;<br>> phydbl logbig;<br>> phydbl inv_site_lk;<br>> + phydbl tree_site_lk_cat[tree->mod->n_catg];<br>> <br>> logbig = LOG((phydbl)BIG);<br>> <br>> @@ -451,7 +468,6 @@<br>> site_lk_cat = .0;<br>> ambiguity_check = -1;<br>> state = -1;<br>> - site = tree->curr_site;<br>> ns = tree->mod->ns;<br>> <br>> if((b->rght->tax) && (!tree->mod->s_opt->greedy))<br>> @@ -537,7 +553,7 @@<br>> }<br>> }<br>> }<br>> - tree->site_lk_cat[catg] = site_lk_cat;<br>> + tree_site_lk_cat[catg] = site_lk_cat;<br>> }<br>> <br>> max_sum_scale = (phydbl)BIG;<br>> @@ -562,7 +578,7 @@<br>> Warn_And_Exit("\n");<br>> }<br>> <br>> - tmp = sum + (logbig - LOG(tree->site_lk_cat[catg]))/(phydbl)LOG2;<br>> + tmp = sum + (logbig - LOG(tree_site_lk_cat[catg]))/(phydbl)LOG2;<br>> if(tmp < max_sum_scale) max_sum_scale = tmp; /* min of the maxs */<br>> }<br>> <br>> @@ -575,7 +591,7 @@<br>> {<br>> exponent = -(sum_scale_left_cat[catg]+sum_scale_rght_cat[catg])+fact_sum_scale;<br>> <br>> - site_lk_cat = tree->site_lk_cat[catg];<br>> + site_lk_cat = tree_site_lk_cat[catg];<br>> <br>> if(exponent > 0)<br>> {<br>> @@ -605,12 +621,12 @@<br>> PhyML_Printf("\n+ site=%4d cat=%4d site_lk_cat=%G sum_scale=%d max=%G fact=%d expo=%d dbl=%G",<br>> tree->curr_site,<br>> catg,<br>> - tree->site_lk_cat[catg],<br>> + tree_site_lk_cat[catg],<br>> sum_scale_left_cat[catg]+sum_scale_rght_cat[catg],<br>> max_sum_scale,<br>> fact_sum_scale,<br>> -(sum_scale_left_cat[catg]+sum_scale_rght_cat[catg])+fact_sum_scale,<br>> - (double)tree->site_lk_cat[catg] * pow(2.,-(sum_scale_left_cat[catg]+sum_scale_rght_cat[catg])+fact_sum_scale));<br>> + (double)tree_site_lk_cat[catg] * pow(2.,-(sum_scale_left_cat[catg]+sum_scale_rght_cat[catg])+fact_sum_scale));<br>> <br>> site_lk_cat = BIG / 10;<br>> }<br>> @@ -623,12 +639,12 @@<br>> PhyML_Printf("\n- site=%4d cat=%4d site_lk_cat=%G sum_scale=%d max=%G fact=%d expo=%d dbl=%G",<br>> tree->curr_site,<br>> catg,<br>> - tree->site_lk_cat[catg],<br>> + tree_site_lk_cat[catg],<br>> sum_scale_left_cat[catg]+sum_scale_rght_cat[catg],<br>> max_sum_scale,<br>> fact_sum_scale,<br>> -(sum_scale_left_cat[catg]+sum_scale_rght_cat[catg])+fact_sum_scale,<br>> - (double)tree->site_lk_cat[catg] * pow(2.,-(sum_scale_left_cat[catg]+sum_scale_rght_cat[catg])+fact_sum_scale));<br>> + (double)tree_site_lk_cat[catg] * pow(2.,-(sum_scale_left_cat[catg]+sum_scale_rght_cat[catg])+fact_sum_scale));<br>> <br>> Exit("\n");<br>> }<br>> @@ -636,13 +652,13 @@<br>> site_lk_cat = .0;<br>> }<br>> <br>> - tree->site_lk_cat[catg] = site_lk_cat;<br>> + tree_site_lk_cat[catg] = site_lk_cat;<br>> }<br>> <br>> site_lk = .0;<br>> For(catg,tree->mod->n_catg)<br>> {<br>> - site_lk += tree->site_lk_cat[catg] * tree->mod->gamma_r_proba[catg];<br>> + site_lk += tree_site_lk_cat[catg] * tree->mod->gamma_r_proba[catg];<br>> }<br>> <br>> /* The substitution model does include invariable sites */<br>> @@ -677,7 +693,7 @@<br>> <br>> log_site_lk = LOG(site_lk) - (phydbl)LOG2 * fact_sum_scale;<br>> <br>> - For(catg,tree->mod->n_catg) tree->log_site_lk_cat[catg][site] = LOG(tree->site_lk_cat[catg]) - (phydbl)LOG2 * fact_sum_scale;<br>> + For(catg,tree->mod->n_catg) tree->log_site_lk_cat[catg][site] = LOG(tree_site_lk_cat[catg]) - (phydbl)LOG2 * fact_sum_scale;<br>> <br>> if(isinf(log_site_lk) || isnan(log_site_lk))<br>> {<br>> @@ -694,7 +710,6 @@<br>> /* Multiply log likelihood by the number of times this site pattern is found in the data */<br>> tree->c_lnL_sorted[site] = tree->data->wght[site]*log_site_lk;<br>> <br>> - tree->c_lnL += tree->data->wght[site]*log_site_lk;<br>> /* tree->sum_min_sum_scale += (int)tree->data->wght[site]*min_sum_scale; */<br>> <br>> return log_site_lk;<br>> @@ -1118,6 +1133,7 @@<br>> Pij2 = d->b[dir2]->Pij_rr;<br>> <br>> /* For every site in the alignment */<br>> + #pragma omp parallel for private(state_v1,state_v2,ambiguity_check_v1,ambiguity_check_v2,catg,i,p1_lk1,p2_lk2) <br>> For(site,n_patterns)<br>> {<br>> state_v1 = state_v2 = -1;<br>> @@ -1399,6 +1415,7 @@<br>> Pij2 = d->b[dir2]->Pij_rr;<br>> <br>> /* For every site in the alignment */<br>> + #pragma omp parallel for private(state_v1,state_v2,ambiguity_check_v1,ambiguity_check_v2,catg,i,p1_lk1,p2_lk2) <br>> For(site,n_patterns)<br>> {<br>> state_v1 = state_v2 = -1;<br>> @@ -2234,13 +2251,13 @@<br>> sides of t_edge *b are up-to-date. Calculate the log-likelihood at one site.<br>> */<br>> #ifdef USE_OLD_LK<br>> -phydbl Lk_Core(t_edge *b, t_tree *tree)<br>> +phydbl Lk_Core(t_edge *b, t_tree *tree, int site)<br>> {<br>> phydbl log_site_lk, site_lk, site_lk_cat;<br>> phydbl scale_left, scale_rght;<br>> phydbl sum;<br>> int ambiguity_check,state;<br>> - int catg,ns,k,l,site;<br>> + int catg,ns,k,l;<br>> int dim1,dim2,dim3;<br>> <br>> <br>> @@ -2253,7 +2270,6 @@<br>> site_lk_cat = .0;<br>> ambiguity_check = -1;<br>> state = -1;<br>> - site = tree->curr_site;<br>> ns = tree->mod->ns;<br>> <br>> tree->old_site_lk[site] = tree->cur_site_lk[site];<br>> @@ -2383,7 +2399,7 @@<br>> tree->cur_site_lk[site] = log_site_lk;<br>> /* Multiply log likelihood by the number of times this site pattern is found oin the data */<br>> tree->c_lnL_sorted[site] = tree->data->wght[site]*log_site_lk;<br>> - tree->c_lnL += tree->c_lnL_sorted[site];<br>> +<br>> return log_site_lk;<br>> }<br>> <br>> @@ -2492,6 +2508,7 @@<br>> Pij2 = d->b[dir2]->Pij_rr;<br>> <br>> /* For every site in the alignment */<br>> + #pragma omp parallel for private(scale_v1,scale_v2,state_v1,state_v2,ambiguity_check_v1,ambiguity_check_v2,catg,i,j,p1_lk1,p2_lk2,max_p_lk) <br>> For(site,n_patterns)<br>> {<br>> /* Current scaling values at that site */<br>> Index: src/lk.h<br>> ===================================================================<br>> --- src/lk.h (revisi??n: 582)<br>> +++ src/lk.h (copia de trabajo)<br>> @@ -51,7 +51,7 @@<br>> phydbl Update_Lk_At_Given_Edge(t_edge *b_fcus, t_tree *tree);<br>> void Update_P_Lk_Greedy(t_tree *tree, t_edge *b_fcus, t_node *n);<br>> void Get_All_Partial_Lk_Scale_Greedy(t_tree *tree, t_edge *b_fcus, t_node *a, t_node *d);<br>> -phydbl Lk_Core(t_edge *b, t_tree *tree);<br>> +phydbl Lk_Core(t_edge *b, t_tree *tree, int site);<br>> phydbl Lk_Triplet(t_node *a, t_node *d, t_tree *tree);<br>> void Print_Lk_Given_Edge_Recurr(t_node *a, t_node *d, t_edge *b, t_tree *tree);<br>> phydbl *Post_Prob_Rates_At_Given_Edge(t_edge *b, phydbl *post_prob, t_tree *tree);<br><br><br>-- <br>http://fam-tille.de<br></div></div></body></html>